-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion 25-String
78 lines (35 loc) · 978 Bytes
/
Question 25-String
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Given two strings s and t , write a function to determine if t is an anagram of s.
Input: s = "anagram", t = "nagaram"
Output: True
Input: s = "rat", t = "car"
Output: False
def check_anagram(sentence_1,sentence_2):
sentence_2 = sentence_2.lower()
sentence_1 = sentence_1.lower()
#write your code here
m = len(sentence_1)
n = len(sentence_2)
if m==0 or n==0:
return False
helper_dict = {}
for letter in sentence_1:
if letter in helper_dict:
helper_dict[letter]+=1
else:
if letter!=" ":
helper_dict[letter]=1
for letter in sentence_2:
if letter in helper_dict:
helper_dict[letter]-=1
else:
if letter!=" ":
return False
for letter in helper_dict.keys():
if helper_dict[letter]>0:
return False
return True
return res
if __name__ == "__main__":
sentence_1 = "anagram"
sentence_2 = "anagram"
print(check_anagram(sentence_1,sentence_2))