LeetCode算法笔记–零矩阵
01.08. 零矩阵
题目:
编写一种算法,若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]
]
我的解答:
1 | /** |
编写一种算法,若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]
]
1 | /** |
jsonContent: meta: false pages: false posts: title: true date: true path: true text: false raw: false content: false slug: false updated: false comments: false link: false permalink: false excerpt: false categories: true tags: true