leetcode 之Set Matrix Zeroes(10)

设置两个布尔数组,记录行和列是否存在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)的更多相关文章
- 【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. 思路:不能用 ...
- [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 ...
- 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. 解题思路: ...
- Leetcode#73 Set Matrix Zeroes
原题地址 用矩形的第一行和第一列充当mask 代码: void setZeroes(vector<vector<int> > &matrix) { ].empty()) ...
- [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 ...
- 【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 ...
- 【LeetCode】Set Matrix Zeroes 解题报告
今天看到CSDN博客的勋章换了图表,同一时候也添加显示了博客等级,看起来都听清新的,感觉不错! [题目] Given a m x n matrix, if an element is 0, set i ...
- leetcode[73] Set Matrix Zeroes 将矩阵置零
给定一个矩阵,把零值所在的行和列都置为零.例如: 1 2 3 1 3 1 1 1 操作之后变为 1 3 0 0 0 1 1 方法1: 赋值另存一个m*n的矩阵,在原矩阵为零的值相应置新的矩阵行和列为零 ...
- 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 ...
随机推荐
- Android 职业路上--只要还有一丝希望,不到最后一刻,不要轻言放弃--从屌丝到进入名企
写在前面:只要还有一丝希望,不到最后一刻,不要轻言放弃! 来到西安十来天了,现在基本安顿下来了,这几天在工作中也遇到一些技术问题,但都没来得及总结分享,现在想和大家分享一下我的工作求职经历! 接触an ...
- BZOJ4003:[JLOI2015]城池攻占——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4003 https://www.luogu.org/problemnew/show/P3261 小铭 ...
- BZOJ1604 & 洛谷2906:[USACO2008 OPEN]Cow Neighborhoods 奶牛的邻居——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1604 https://www.luogu.org/problemnew/show/P2906#sub ...
- BZOJ3052 & UOJ58:[WC2013]糖果公园——题解
http://uoj.ac/problem/58 http://www.lydsy.com/JudgeOnline/problem.php?id=3052 输入格式 输出格式 input 4 3 5 ...
- BZOJ2223:[Coci2009]PATULJCI——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2223 Description Sample Input 10 3 1 2 1 2 1 2 3 2 3 ...
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
- [IOI2007]Miners 矿工配餐
link 其实就是一个比较简单的$IOI$题.简单$dp$就行,设$5$维$dp$即可 最后在滚动一下,判一下可行性即可. #include<iostream> #include<c ...
- poco普通线程
#include "Poco/Thread.h" #include "Poco/RunnableAdapter.h" #include <iostream ...
- bzoj 3246 [Ioi2013]Dreaming 贪心
[Ioi2013]Dreaming Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 638 Solved: 241[Submit][Status][Di ...
- Qt error ------ 出现Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
出现原因: 使用了不存在的对象 数组越界了 用 delete 释放未分配的内存空间,或者超过一次释放同个内存 比如: 顺序不能颠倒 正确: ui->setupUi(this); ui->t ...