0%

Lintcode刷题/55.比较字符串

比较字符串

描述

比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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):
# write your code here
#此题采用了反向思维的方法,通过举出返回Flase的几种情况后,其余都是True

if len(A) < len(B):
return False
if len(A) == len(B):
return(sorted(A) == sorted(B))
for i in B:
if A.count(i) < B.count(i):
return False
return True