-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring.py
More file actions
executable file
·36 lines (30 loc) · 882 Bytes
/
string.py
File metadata and controls
executable file
·36 lines (30 loc) · 882 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
27
28
29
30
31
32
33
34
35
36
# -*- coding:utf-8 -*-
class Same:
def checkSam(self, stringA, stringB):
# write code here
lA = list(stringA); lB = list(stringB)
dA = {}; dB = {}
for a in lA:
if dA.has_key(a):
dA[a] += 1
else:
dA.setdefault(a,1)
for b in lB:
if not dA.has_key(b):
return False
else:
dA[b] -= 1
if dA[b]<0:
return False
return True
def main():
sol = Same()
#"This is nowcoder","is This nowcoder"
if sol.checkSam("here you are","are you here"):
print 'true'
else:
print 'false'
if sol.checkSam("This is nowcoder","is This nowcoder"):
print True
if __name__ == '__main__':
main()