Skip to content

Commit 12cfd41

Browse files
Check Permutation Done
1 parent 2738936 commit 12cfd41

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'''
2+
Check Permutation: Given two strings, write a method to decide if one is a permutation of the
3+
other.
4+
Hints: #1, #84, #122, #131
5+
'''
6+
'''
7+
PS: Assuming String to be 256 unicoded
8+
'''
9+
10+
def Check_Permutation(str1, str2):
11+
12+
str1 = str1.lower()
13+
str2 = str2.lower()
14+
15+
#edge case
16+
if(len(str1) != len(str2)):
17+
return False
18+
19+
count = [0] * 256
20+
21+
for i in range(len(str1)):
22+
count[ord(str1[i])] += 1
23+
count[ord(str2[i])] -= 1
24+
25+
for i in range(256):
26+
if (count[i] != 0):
27+
return False
28+
29+
return True
30+
31+
if __name__ == '__main__':
32+
str1 = input("Enter First Word >> ")
33+
str2 = input("Enter Second Word >> ")
34+
answer = Check_Permutation(str1.strip(), str2.strip())
35+
print(answer)

0 commit comments

Comments
 (0)