Skip to content

Commit 4758cc6

Browse files
sol for 1.2
1 parent a0e417a commit 4758cc6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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

0 commit comments

Comments
 (0)