设置两个布尔数组,记录行和列是否存在0。需要注意的是如何将行或列设为0.

void setZeros(vector<vector<int>> &matrix)
{
int m = matrix.size();
int n = matrix[].size(); vector<bool>row(m, false);
vector<bool>col(n, false); for (int i = ; i < m;i++)
for (int j = ; j < n; j++)
{
if (matrix[i][j] == )
row[i] = col[j] = true;
} for (int i = ; i < m; i++)
{
if (row[i] == true)
fill(&matrix[i][], &matrix[i][] + n, );
}
for (int j = ; j < n; j++)
{
if (col[j] == true)
{
for (int i = ; i < m; i++)
matrix[i][j] = ;
}
}

leetcode 之Set Matrix Zeroes(10)的更多相关文章

  1. 【leetcode】Set Matrix Zeroes(middle)

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 思路:不能用 ...

  2. [LeetCode] 73. Set Matrix Zeroes 矩阵赋零

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Exampl ...

  3. Java for LeetCode 073 Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 解题思路: ...

  4. Leetcode#73 Set Matrix Zeroes

    原题地址 用矩形的第一行和第一列充当mask 代码: void setZeroes(vector<vector<int> > &matrix) { ].empty()) ...

  5. [LeetCode] 73. Set Matrix Zeroes 解题思路

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow ...

  6. 【Leetcode】Set Matrix Zeroes

    给定一个m x n的矩阵,如果某个元素为0,则把该元素所在行和列全部置0. Given a m x n matrix, if an element is 0, set its entire row a ...

  7. 【LeetCode】Set Matrix Zeroes 解题报告

    今天看到CSDN博客的勋章换了图表,同一时候也添加显示了博客等级,看起来都听清新的,感觉不错! [题目] Given a m x n matrix, if an element is 0, set i ...

  8. leetcode[73] Set Matrix Zeroes 将矩阵置零

    给定一个矩阵,把零值所在的行和列都置为零.例如: 1 2 3 1 3 1 1 1 操作之后变为 1 3 0 0 0 1 1 方法1: 赋值另存一个m*n的矩阵,在原矩阵为零的值相应置新的矩阵行和列为零 ...

  9. Leetcode 073 Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

随机推荐

  1. BZOJ5343 & 洛谷4602 & LOJ2555:[CTSC2018]混合果汁——题解

    https://www.luogu.org/problemnew/show/P4602 https://loj.ac/problem/2555 https://www.lydsy.com/JudgeO ...

  2. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  3. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  4. HDOJ.1029 Ignatius and the Princess IV(map)

    Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...

  5. lnmp架构 实现lbs资料参考

    查找附近的xxx 球面距离以及Geohash方案探讨 http://www.wubiao.info/372 http://digdeeply.org/archives/06152067.html

  6. React注释

    React中注释有以下三种 var content = ( <Nav> {/* 一般注释, 用 {} 包围 */} <Person /* 多 行 注释 */ name={window ...

  7. 使用C#解析并运行JavaScript代码

    如果想在C#编程中解析并运行JavaScript代码,常见的方式有两种: 利用COM组件“Microsoft Script Control”,可参见:C#使用技巧之调用JS脚本方法一 利用JScrip ...

  8. 阿里云配置redis

    一.redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sor ...

  9. Spring知识点复习

    Spring知识点复习 一.专业术语 侵入式设计 引入框架,对现有的类的结构有影响,即需要实现或继承某些特定类.如:Struts框架 非侵入式设计 引入框架,对现有的类结构没有影响.如:Hiberna ...

  10. UVA 1645 Count

    https://vjudge.net/problem/UVA-1645 题意:有多少个n个节点的有根树,每个深度中所有节点的子节点数相同 dp[i] 节点数为i时的答案 除去根节点还有i-1个点,如果 ...