-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvalid.py
More file actions
68 lines (56 loc) · 1.6 KB
/
valid.py
File metadata and controls
68 lines (56 loc) · 1.6 KB
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
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
"""
# --- List comparison method: Time Limit Exceeded
# Anagram validity check
if len(s) > len(t):
check = list(s)
other = list(t)
else:
check = list(t)
other = list(s)
for char in check:
if char not in other:
return False
else:
del other[other.index(char)]
return True
# What if unicode characters occur, solution?
"""
"""
# 100pass = To check if same number of elements occur in both the strings
# Python Hashmap method using collections counter
sc = collections.Counter(s)
tc = collections.Counter(t)
if sc == tc:
return True
else:
return False
"""
"""
# 100 pass - using manual naive hashmap
sc = {}
tc = {}
for char in s:
if char not in sc:
sc[char] = 0
sc[char] += 1
for char in t:
if char not in tc:
tc[char] = 0
tc[char] += 1
if sc == tc:
return True
else:
return False
"""
# 100pass = Easy pythonic hack - using sorted both the sides
if sorted(s) == sorted(t):
return True
else:
return False