01 矩阵
https://www.lintcode.com/problem/974/?utm_source=sc-cheatsheet-cyc
输入:[[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]]输出:[[0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]]输入:[[0,1,0,1,1], [1,1,0,0,1], [0,0,0,1,0], [1,0,1,1,1], [1,0,0,0,1]]输出:[[0,1,0,1,2], [1,1,0,0,1], [0,0,0,1,0], [1,0,1,1,1], [1,0,0,0,1]]
解题思路
direction = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for dx, dy in direction:
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < m:Last updated