forked from yingl/LintCodeInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare_strings.py
More file actions
26 lines (24 loc) · 770 Bytes
/
compare_strings.py
File metadata and controls
26 lines (24 loc) · 770 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
# coding: utf-8
class Solution:
"""
@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
"""
def compareStrings(self, A, B):
# write your code here
if not B:
return True
count = {}
for i, ch in enumerate(B):
if ch not in count:
count[ch] = 1
else:
count[ch] += 1
for i, ch in enumerate(A):
if ch in count:
count[ch] -= 1
if count[ch] == 0:
del(count[ch])
return not count
# easy: http://lintcode.com/zh-cn/problem/compare-strings/