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

这题要注意的就是应该是就地执行,所以可以先采取一个数组将所有0元素的位置记下来,然后一次性的全部置成0即可:

 class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int szHor = matrix.size();
if(szHor == ) return;
int szVer = matrix[].size();
if(szVer == ) return;
vector<int> mark;
mark.clear();
int i, j;
for(i = ; i < szHor; ++i){
for(j = ; j < szVer; ++j){
if(matrix[i][j] == ){
mark.push_back(i);
mark.push_back(j);
}
}
}
int row, col;
int sz = mark.size();
for(int p = ; p < sz; p+=){
for(int m = ; m < szHor; m++){
matrix[m][mark[p + ]] = ;
}
for(int n = ; n < szVer; n++){
matrix[mark[p]][n] = ;
}
} }
};

LeetCode OJ:Set Matrix Zeroes(设置矩阵0元素)的更多相关文章

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

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

  2. 【LeetCode每天一题】Set Matrix Zeroes(设置0矩阵)

    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. LeetCode第[73]题(Java):Set Matrix Zeroes(矩阵置0)

    题目:矩阵置0 难度:Easy 题目内容: Given a m x n matrix, if an element is 0, set its entire row and column to 0. ...

  4. LeetCode 54. Spiral Matrix(螺旋矩阵)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  5. leetcode 【 Set Matrix Zeroes 】python 实现

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

  6. [LeetCode] 59. Spiral Matrix II 螺旋矩阵 II

    Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order. For ...

  7. [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 ...

  8. 【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 ...

  9. [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 ...

随机推荐

  1. 利用EasySQLMAIL实现自动填写Excel表格并发送邮件(2)

    利用EasySQLMAIL实现自动填写Excel表格并发送邮件 转自:http://blog.sina.com.cn/s/blog_1549483b70102witg.html 前一篇博文中记录了“利 ...

  2. Hive学习路线图--张丹老师

    前言 Hive是Hadoop家族中一款数据仓库产品,Hive最大的特点就是提供了类SQL的语法,封装了底层的MapReduce过程,让有SQL基础的业务人员,也可以直接利用Hadoop进行大数据的操作 ...

  3. pkg-config用法和gcc cflags

    pkg-config程序是干什么用的?简单的说就是向用户向程序提供相应库的路径.版本号等信息的程序. 譬如说我们运行以下命令:pkg-config  查看gcc的CFLAGS参数 $pkg-confi ...

  4. ArcEngine开发中“错误类型"****"未定义构造函数”

    from:http://blog.csdn.net/mengdong_zy/article/details/8990593 问题 在ArcEngine开发的时候,在编译时,发现出现这样的错误,出错的地 ...

  5. 使用 libevent 和 libev 提高网络应用性能(IBM)

    http://www.ibm.com/developerworks/cn/aix/library/au-libev/

  6. Hive2.2.1概述(待重写)

    概述 hive 是一个包裹着 hdfs 的壳子,hive 通过 hql,将 sql 翻译成 MR ,进行数据查询. Hive是⼀个构建在Hadoop之上的数据仓库 hive的数据存在hdfs上,元信息 ...

  7. ExtJS + fileuploadfield实现文件上传

    后台服务端接收文件的代码: /** * 后台上传文件处理Action */ @RequestMapping(value = "/uploadFile", method=Reques ...

  8. LigerUI LigerGird IE7/8 下不显示 “in”的操作数无效

    LigerUI IE7/8 下显示 in的操作数无效 修改脚本生成LigerGrid的地方,将最后一列后面的,去掉

  9. List To Json

    命名空间 using Newtonsoft.Json; 实例代码 /// <summary> /// 将list集合转换为json /// </summary> /// < ...

  10. 20162326 《Java程序设计》第3周学习总结

    20162326 <Java程序设计>第3周学习总结 教材学习内容总结 这周我通过课堂学习了VIM的列编辑crtl+v,shift+i shift+a·分别是左侧插入和右侧插入.还学习了使 ...