Skip to content

Commit 22cb4dd

Browse files
committed
Runtime: 1146 ms (Top 40.37%) | Memory: 16.2 MB (Top 99.65%)
1 parent 07f5525 commit 22cb4dd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
# Runtime: 1146 ms (Top 40.37%) | Memory: 16.2 MB (Top 99.65%)
12
class Solution:
23
def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:
34
rows = len(mat)
45
cols = len(mat[0])
5-
6+
67
for i in range(rows):
78
for j in range(cols):
89
if mat[i][j] != 0:
910
top = mat[i-1][j] if i>0 else float('inf')
1011
left = mat[i][j-1] if j>0 else float('inf')
1112
mat[i][j] = 1 + min(top, left)
12-
13+
1314
for i in range(rows-1, -1, -1):
1415
for j in range(cols-1, -1, -1):
1516
if mat[i][j] != 0:
1617
right = mat[i][j+1] if j<cols-1 else float('inf')
1718
bottom = mat[i+1][j] if i<rows-1 else float('inf')
1819
mat[i][j] = min(min(right, bottom)+1, mat[i][j])
19-
20-
21-
return mat
20+
21+
return mat

0 commit comments

Comments
 (0)