File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments