Created
April 8, 2020 15:48
-
-
Save oisincar/31c4623c19a27689ed56487daa78d480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def updateMatrix(self, matrix: List[List[int]]) -> List[List[int]]: | |
dimX, dimY = len(matrix), len(matrix[0]) | |
for i in range(dimX+dimY): | |
#print("mat", matrix) | |
for x in range(dimX): | |
for y in range(dimY): | |
if matrix[x][y] == 0: | |
continue | |
ofX, ofY = [0,0,-1,1], [-1,1,0,0] | |
neighbours = [matrix[x+ofX[j]][y+ofY[j]] for j in range(4) if | |
x+ofX[j] >= 0 and x+ofX[j] < dimX and | |
y+ofY[j] >= 0 and y+ofY[j] < dimY] | |
#print(neighbours) | |
matrix[x][y] = 1+min(neighbours) | |
return matrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment