比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
注意事项
在 A 中出现的 B 字符串里的字符不需要连续或者有序。
没什么难的,正好回顾一下python就用python写了
class Solution:
"""
@param: A: A string
@param: B: A string
@return: if string A contains all of the characters in B return true else return false
"""
def compareStrings(self, A, B):
if not B:
return True
if not A :
return False
dicta = {}
dictb = {}
for i in A:
if i in dicta:
dicta[i] += 1
else:
dicta[i] = 1
for j in B:
if j in dictb:
dictb[j] += 1
else:
dictb[j] = 1
worda = dicta.keys()
for j in B:
if j not in worda or dicta[j] < dictb[j]:
return False
return True