Skip to content

Commit 72a3238

Browse files
authored
Update largest-component-size-by-common-factor.py
1 parent 45f3e89 commit 72a3238

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Python/largest-component-size-by-common-factor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Time: O(f * n), f is the max number of unique prime factors
2-
# Soace: O(f * n)
2+
# Soace: O(p), p is the total number of unique primes
33

44
import collections
55

@@ -51,6 +51,7 @@ def primeFactors(i): # prime factor decomposition
5151
nodesWithCommonFactor = collections.defaultdict(list)
5252
for i in xrange(len(A)):
5353
for factor in primeFactors(A[i]):
54-
nodesWithCommonFactor[factor].append(i)
54+
if not nodesWithCommonFactor[factor]:
55+
nodesWithCommonFactor[factor].append(i)
5556
union_find.union_set(nodesWithCommonFactor[factor][0], i)
5657
return max(union_find.size)

0 commit comments

Comments
 (0)