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 ...
随机推荐
- BZOJ5323 & 洛谷4562:[JXOI2018]游戏——题解
https://www.luogu.org/problemnew/show/P4562 https://www.lydsy.com/JudgeOnline/problem.php?id=5323 (B ...
- UVA.548 Tree(二叉树 DFS)
UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后D ...
- Redux的State不应该全部放在Store里
使用了redux管理应用的状态,应用的状态不应该全部放在Store里面. 前端状态主要有一下两种: 1. Domain data 2. UI State 1. Domain data 来自于服务端对领 ...
- 51nod 1274 最长递增路径(DP)
一开始自己想了一种跑的巨慢..写了题解的做法又跑的巨快..一脸懵逼 显然要求边权递增就不可能经过重复的边了,那么设f[i]为第i条边出发能走多远就好了,这是我一开始的写法,可能dfs冗余状态较多,跑的 ...
- sql 中sum函数返回null的解决方案
SUM 是SQL语句中的标准求和函数,如果没有符合条件的记录,那么SUM函数会返回NULL. 但多数情况下,我们希望如果没有符合条件记录的情况下,我们希望它返回0,而不是NULL,那么我们可以使用例如 ...
- ImageNet: what is top-1 and top-5 error rate?
https://stats.stackexchange.com/questions/156471/imagenet-what-is-top-1-and-top-5-error-rate Your cl ...
- POJ3974:Palindrome(Manacher模板)
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 14021 Accepted: 5374 题目链接 ...
- MEF——.NET中值得体验的精妙设计
摘要:.NET 是 Microsoft XML Web services 平台.MEF是.NET Framework 4.0一个重要的库,Visual Studio 2010 Code Editor的 ...
- js的作用域深入理解
一.什么是作用域 作用域是指对某一变量和方法具有访问权限的代码空间,Javascript的作用域只有两种:全局作用域和本地作用域,本地作用域是按照函数来区分的(即全局变量和局部变量)) 局部变量:只有 ...
- 9.python爬虫--pyspider
pyspider简介 PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI.采用Python语言编写,分布式架构,支持多种数据库后端,强大的WebUI支持脚本编辑器,任务监视器,项 ...