valid for 40/70 test cases

This commit is contained in:
Jacob Delgado 2023-08-06 15:48:17 -07:00
parent fecfc3da14
commit 909465a1ee

View File

@ -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