Skip to content

Commit 0060e9e

Browse files
committed
Runtime: 170 ms (Top 85.91%) | Memory: 15.7 MB (Top 23.94%)
1 parent bedb5e1 commit 0060e9e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Runtime: 170 ms (Top 85.91%) | Memory: 15.7 MB (Top 23.94%)
12
class Solution:
23
def minDays(self, grid: List[List[int]]) -> int:
34
cnt = 0
@@ -6,20 +7,20 @@ def minDays(self, grid: List[List[int]]) -> int:
67
if grid[i][j]:
78
cnt += 1 # count the number of elements
89
root = (i, j) # assign the root node for the graph
9-
10-
if cnt <= 1 : return cnt # no elements in the map
11-
10+
11+
if cnt <= 1 : return cnt # no elements in the map
12+
1213
vis, low, time, res = {root}, {}, {}, []
13-
14+
1415
# find whether articulation points are present in the matrix
15-
def articulation_points(curr, parent):
16+
def articulation_points(curr, parent):
1617
low[curr] = time[curr] = len(vis)
1718
children = 0
1819
i, j = curr
19-
20+
2021
for x, y in [(i+1, j), (i-1, j), (i, j+1), (i, j-1)]:
2122
if (x, y) == parent : continue
22-
23+
2324
if 0<=x<len(grid) and 0<=y<len(grid[0]) and grid[x][y]:
2425
if (x, y) not in vis:
2526
vis.add((x,y))
@@ -30,7 +31,7 @@ def articulation_points(curr, parent):
3031
res.append([i, j])
3132
else:
3233
low[curr] = min(low[curr], time[(x, y)])
33-
34+
3435
if parent == (-1, -1) and children > 1:
3536
res.append([x, y])
3637

@@ -42,4 +43,3 @@ def articulation_points(curr, parent):
4243
return 1
4344
else: # worst case, no articulation points
4445
return 2
45-

0 commit comments

Comments
 (0)