We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 45f3e89 commit 72a3238Copy full SHA for 72a3238
Python/largest-component-size-by-common-factor.py
@@ -1,5 +1,5 @@
1
# Time: O(f * n), f is the max number of unique prime factors
2
-# Soace: O(f * n)
+# Soace: O(p), p is the total number of unique primes
3
4
import collections
5
@@ -51,6 +51,7 @@ def primeFactors(i): # prime factor decomposition
51
nodesWithCommonFactor = collections.defaultdict(list)
52
for i in xrange(len(A)):
53
for factor in primeFactors(A[i]):
54
- nodesWithCommonFactor[factor].append(i)
+ if not nodesWithCommonFactor[factor]:
55
+ nodesWithCommonFactor[factor].append(i)
56
union_find.union_set(nodesWithCommonFactor[factor][0], i)
57
return max(union_find.size)
0 commit comments