Skip to content

Commit a424b3b

Browse files
committed
Runtime: 1782 ms (Top 87.91%) | Memory: 16.6 MB (Top 91.21%)
1 parent 1bb383a commit a424b3b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

scripts/algorithms/M/Minimize Malware Spread/Minimize Malware Spread.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Runtime: 1782 ms (Top 87.91%) | Memory: 16.6 MB (Top 91.21%)
12
class Solution:
23
def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:
34
n = len(graph)
@@ -6,9 +7,9 @@ def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:
67
for j in range(n):
78
if graph[i][j]:
89
uf.union(i, j)
9-
10+
1011
max_remove = 0
11-
12+
1213
initial.sort()
1314
min_index = initial[0]
1415
for i in range(len(initial)):
@@ -25,23 +26,20 @@ def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:
2526
min_index = initial[i]
2627

2728
return min_index
28-
29-
30-
31-
29+
3230
class UnionFind:
3331
def __init__(self, size):
3432
self.parent = {}
3533
self.rank = {}
3634
for i in range(size):
3735
self.parent[i] = i
3836
self.rank[i] = 1
39-
37+
4038
def find(self, x):
4139
if x != self.parent[x]:
4240
x = self.find(self.parent[x])
4341
return x
44-
42+
4543
def union(self, x, y):
4644
px, py = self.find(x), self.find(y)
4745
if px == py: return
@@ -50,4 +48,4 @@ def union(self, x, y):
5048
self.rank[px] += self.rank[py]
5149
else:
5250
self.parent[px] = py
53-
self.rank[py] += self.rank[px]
51+
self.rank[py] += self.rank[px]

0 commit comments

Comments
 (0)