File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Python/chapter01/1.2 - Check Perm Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ def perm_check (str_1 ,str_2 ):
2
+ if len (str_1 ) != len (str_2 ):#If both str are diiferent lenghts return false
3
+ return False
4
+ d = {}
5
+ for i in str_1 : #takes all the letter in string one and add them to the hash map
6
+ if i in d : #counts the number of letter
7
+ d [i ] += 1
8
+ else :
9
+ d [i ] = 1
10
+
11
+ for j in str_2 : #
12
+ if j in d :#Looks at the letter in the string and subtract the number
13
+ #of the same letter from the value
14
+ d [j ] -= 1
15
+ else :
16
+ d [j ] = 1
17
+
18
+ for keys ,value in d .items ():
19
+ if value > 0 :
20
+ return False
21
+ return True
22
+
23
+
24
+ #O(n) sol?
25
+ print (perm_check ("camilo" ,"pop" )) #False
26
+
27
+ print (perm_check ("camilo" ,"camplo" )) #false
28
+
29
+ print (perm_check ("camilo" ,"olimac" )) #True
You can’t perform that action at this time.
0 commit comments