Skip to content

Commit 92f6c84

Browse files
authored
Update similar-string-groups.py
1 parent 2fe62fa commit 92f6c84

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Python/similar-string-groups.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Time: O(n * l * min(n, l^2))
2-
# Space: O(n * l^3)
1+
# Time: O(n^2 * l) ~ O(n * l^4)
2+
# Space: O(n) ~ O(n * l^3)
33

44
# Two strings X and Y are similar if we can swap two letters
55
# (in different positions) of X, so that it equals Y.
@@ -92,7 +92,7 @@ def isSimilar(a, b):
9292
word[j1], word[j2] = word[j2], word[j1]
9393
buckets["".join(word)].append(i)
9494
word[j1], word[j2] = word[j2], word[j1]
95-
for word in A:
95+
for word in A: # Time: O(n * l^4)
9696
for i1, i2 in itertools.combinations(buckets[word], 2):
9797
union_find.union_set(i1, i2)
9898
return union_find.size()

0 commit comments

Comments
 (0)