forked from algorhythms/LintCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompare Strings.py
More file actions
26 lines (22 loc) · 748 Bytes
/
Compare Strings.py
File metadata and controls
26 lines (22 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Compare two strings A and B, determine whether A contains all of the characters in B.
"""
__author__ = 'Danyang'
class Solution:
def compareStrings(self, A, B):
"""
Straightforward
:param A : A string includes Upper Case letters
:param B : A string includes Upper Case letters
:return : if string A contains all of the characters in B return True else return False
"""
cnt = [0 for _ in xrange(26)]
for c in A:
cnt[ord(c)-ord('A')] += 1
for c in B:
cnt[ord(c)-ord('A')] -= 1
if cnt[ord(c)-ord('A')]<0:
return False
return True
if __name__=="__main__":
assert Solution().compareStrings("A", "")==True