Skip to content

Commit fc11a58

Browse files
committed
比较字符串
1 parent b2c14b2 commit fc11a58

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compare_strings.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
"""
5+
@param A : A string includes Upper Case letters
6+
@param B : A string includes Upper Case letters
7+
@return : if string A contains all of the characters in B return True else return False
8+
"""
9+
def compareStrings(self, A, B):
10+
# write your code here
11+
if not B:
12+
return True
13+
count = {}
14+
for i, ch in enumerate(B):
15+
if ch not in count:
16+
count[ch] = 1
17+
else:
18+
count[ch] += 1
19+
for i, ch in enumerate(A):
20+
if ch in count:
21+
count[ch] -= 1
22+
if count[ch] == 0:
23+
del(count[ch])
24+
return not count

0 commit comments

Comments
 (0)