valid for 40/70 test cases
This commit is contained in:
parent
fecfc3da14
commit
909465a1ee
@ -23,19 +23,27 @@ def groupAnagrams(strs: list[str])->list[str]:
|
||||
:type strs: List[str]
|
||||
:rtype: List[List[str]]
|
||||
"""
|
||||
grouped = []
|
||||
final = []
|
||||
seen = []
|
||||
# Fill first list with matching anagrams
|
||||
for i in range(len(strs)):
|
||||
for j in range(i+1, len(strs)):
|
||||
if validAnagram(strs[i], strs[j]) == True:
|
||||
if i in grouped:
|
||||
if j in grouped:
|
||||
grouped.append(strs[j])
|
||||
else:
|
||||
grouped = []
|
||||
print(f'i is: {strs[i]}')
|
||||
if i == len(strs)-1 and strs[i] not in grouped:
|
||||
grouped.append(strs[i])
|
||||
for j in range(i+1, len(strs)):
|
||||
print(f'j is: {strs[j]}')
|
||||
if validAnagram(strs[i], strs[j]) == True:
|
||||
if strs[i] not in grouped and strs[i] not in seen:
|
||||
grouped.append(strs[i])
|
||||
seen.append(strs[i])
|
||||
if strs[j] not in grouped and strs[j] not in seen:
|
||||
grouped.append(strs[j])
|
||||
seen.append(strs[j])
|
||||
if grouped:
|
||||
final.append(grouped)
|
||||
|
||||
|
||||
return grouped
|
||||
return final
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user