We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2fe62fa commit 92f6c84Copy full SHA for 92f6c84
1 file changed
Python/similar-string-groups.py
@@ -1,5 +1,5 @@
1
-# Time: O(n * l * min(n, l^2))
2
-# Space: O(n * l^3)
+# Time: O(n^2 * l) ~ O(n * l^4)
+# Space: O(n) ~ O(n * l^3)
3
4
# Two strings X and Y are similar if we can swap two letters
5
# (in different positions) of X, so that it equals Y.
@@ -92,7 +92,7 @@ def isSimilar(a, b):
92
word[j1], word[j2] = word[j2], word[j1]
93
buckets["".join(word)].append(i)
94
95
- for word in A:
+ for word in A: # Time: O(n * l^4)
96
for i1, i2 in itertools.combinations(buckets[word], 2):
97
union_find.union_set(i1, i2)
98
return union_find.size()
0 commit comments