Skip to content

Commit 2fe62fa

Browse files
authored
Update similar-string-groups.py
1 parent 47b5bb1 commit 2fe62fa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/similar-string-groups.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ def isSimilar(a, b):
8282
union_find.union_set(i1, i2)
8383
else:
8484
buckets = collections.defaultdict(list)
85+
lookup = set()
8586
for i in xrange(len(A)):
8687
word = list(A[i])
87-
buckets["".join(word)].append(i)
88+
if A[i] not in lookup:
89+
buckets[A[i]].append(i)
90+
lookup.add(A[i])
8891
for j1, j2 in itertools.combinations(xrange(L), 2):
8992
word[j1], word[j2] = word[j2], word[j1]
9093
buckets["".join(word)].append(i)

0 commit comments

Comments
 (0)