Skip to content

Commit da16bab

Browse files
authored
fix hash_table variable type
1 parent db42f2b commit da16bab

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

group-anagrams/bhyun-kim.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@
2929

3030
class Solution:
3131
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
32-
hash_table = []
33-
counters = []
32+
33+
hash_table = dict()
34+
output = []
35+
3436
for s in strs:
35-
count_s = "".join(sorted(s))
37+
count_s = ''.join(sorted(s))
3638
if count_s in hash_table:
37-
idx = hash_table.index(count_s)
38-
counters[idx].append(s)
39+
idx = hash_table[count_s]
40+
output[idx].append(s)
3941
else:
40-
hash_table.append(count_s)
41-
counters.append([s])
42+
hash_table[count_s] = len(output)
43+
output.append([s])
44+
45+
return output
4246

43-
return counters

0 commit comments

Comments
 (0)