leetcode73
public class Solution
{
public void SetZeroes(int[,] matrix)
{
var row = matrix.GetLength();
var col = matrix.GetLength();
var listrow = new Dictionary<int, int>();
var listcol = new Dictionary<int, int>();
for (int i = ; i < row; i++)
{
for (int j = ; j < col; j++)
{
if (matrix[i, j] == )
{
if (!listrow.ContainsKey(i))
{
listrow.Add(i, );
}
if (!listcol.ContainsKey(j))
{
listcol.Add(j, );
}
}
}
}
foreach (var l in listrow)
{
for (int j = ; j < col; j++)
{
matrix[l.Key, j] = ;
}
}
foreach (var l in listcol)
{
for (int i = ; i < row; i++)
{
matrix[i, l.Key] = ;
}
}
}
}
leetcode73的更多相关文章
- 【leetcode73】经典算法-Guess Number Higher or Lower
题目描述: 从1-n中,随便的拿出一个数字,你来猜测. 提示 提供一个guess(int num)的api,针对猜测的数字,返回三个数值.0,-1,1 0;猜中返回num -1:比猜测的数值小 1:比 ...
- [Swift]LeetCode73. 矩阵置零 | 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 ...
- 【leetcode-73】 矩阵置零
给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [ [1,1,1], [1,0,1], [1,1,1] ] 输 ...
- leetcode73矩阵置零
https://leetcode-cn.com/problems/set-matrix-zeroes/ 解答: 两种方法时间复杂度都为O(mn) O(m+n)空间方法: 用两个容器储存为0的行和列 c ...
- Leetcode73. Set Matrix Zeroes矩阵置零
给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [ [1,1,1], [1,0,1], [1,1,1] ] 输 ...
- LeetCode73 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.(Me ...
- leetcode73:minmum-window-substring
题目描述 给出两个字符串S和T,要求在O(n)的时间复杂度内在S中找出最短的包含T中所有字符的子串. 例如: S ="ADOBECODEBANC" T ="ABC&quo ...
- leetcode探索中级算法
leetcode探索中级答案汇总: https://leetcode-cn.com/explore/interview/card/top-interview-questions-medium/ 1)数 ...
随机推荐
- Rails 5 Test Prescriptions 第5章 Testing Models
Rails,model层包含业务逻辑和储存逻辑.其中储存逻辑被ActiveRecord处理. 在model中,不是每件事都必须是ActiveRecord对象.model layer可以包含各种服务,对 ...
- voj 1754 spfa
最优贸易 最优贸易 描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 ...
- 97. Interleaving String *HARD* -- 判断s3是否为s1和s2交叉得到的字符串
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- C++ 类型转换的特殊用法
C++ 类型转换的特殊用法 下面是ossimLsrRay.h中的一个例子 /*! * CASTING OPERATOR: ossimEcefRay() * Looks like a construct ...
- (转载)Nginx/LVS/HAProxy三种主流负载均衡软件的对比
原地址:http://www.ha97.com/5646.html PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些 ...
- java的继承(编程思想)
继承语法: extends 初始化基类: 由于现在设计基类和导出类两个类,而不是一个类,所以要试着想像导出类锁产生的结果对象,会有些困惑.从外部看来,它就像是一个与基类具有相同接口的新类,或许还会有一 ...
- timer Compliant Controller project (2)--Project Demonstration
1software flow diagram As we know, Embedded design is the core of Electronic Product Design. Di ...
- webdriver的2种等待
隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间,默认值是0,但是设置之后,这个时间将在WebDriver对象实例整个生命周期都起作用 driver.man ...
- jquery插件与扩展一
要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...
- PHP 中的文本截取分析之效率
PHP 中的文本截取分析之效率 在使用 ThinkPHP 或 Laravel 时都会有用到文本截取的帮助函数. 分别是 msubstr (ThinkPHP 3,ThinkPHP 5 没找到) mb_s ...