We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 07f5525 commit 22cb4ddCopy full SHA for 22cb4dd
scripts/algorithms/0-9/01 Matrix/01 Matrix.py
@@ -1,21 +1,21 @@
1
+# Runtime: 1146 ms (Top 40.37%) | Memory: 16.2 MB (Top 99.65%)
2
class Solution:
3
def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:
4
rows = len(mat)
5
cols = len(mat[0])
-
6
+
7
for i in range(rows):
8
for j in range(cols):
9
if mat[i][j] != 0:
10
top = mat[i-1][j] if i>0 else float('inf')
11
left = mat[i][j-1] if j>0 else float('inf')
12
mat[i][j] = 1 + min(top, left)
13
14
for i in range(rows-1, -1, -1):
15
for j in range(cols-1, -1, -1):
16
17
right = mat[i][j+1] if j<cols-1 else float('inf')
18
bottom = mat[i+1][j] if i<rows-1 else float('inf')
19
mat[i][j] = min(min(right, bottom)+1, mat[i][j])
20
21
- return mat
+ return mat
0 commit comments