Skip to content

Commit 2552afe

Browse files
authored
Create string_permutation.py
1 parent 5f3686e commit 2552afe

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

string_permutation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
"""
5+
@param: A: a string
6+
@param: B: a string
7+
@return: a boolean
8+
"""
9+
def Permutation(self, A, B):
10+
# write your code here
11+
di = {}
12+
for s in A:
13+
if s not in di:
14+
di[s] = 1
15+
else:
16+
di[s] += 1
17+
for s in B:
18+
if s not in di:
19+
return False
20+
else:
21+
di[s] -= 1
22+
for k, v in di.items():
23+
if v != 0:
24+
return False
25+
return True
26+
27+
# esay: http://lintcode.com/zh-cn/problem/string-permutation/

0 commit comments

Comments
 (0)