标签:bsp solution int http cci mod append sel ret
编写一种算法,若M × N矩阵中某个元素为0,则将其所在的行与列清零。
示例 1:
输入:
[
[1,1,1],
[1,0,1],
[1,1,1]
]
输出:
[
[1,0,1],
[0,0,0],
[1,0,1]
]
示例 2:
输入:
[
[0,1,2,0],
[3,4,5,2],
[1,3,1,5]
]
输出:
[
[0,0,0,0],
[0,4,5,0],
[0,3,1,0]
]
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/zero-matrix-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
ls=[]
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j]==0:
ls.append([i,j])
for x in ls:
i,j=x[0],x[1]
for m in range(len(matrix)):
for n in range(len(matrix[m])):
if m==i or n==j:
matrix[m][n]=0
标签:bsp solution int http cci mod append sel ret
原文地址:https://www.cnblogs.com/hqzxwm/p/14140712.html