当前位置:网站首页>73. matrix zeroing (marking method)
73. matrix zeroing (marking method)
2022-06-12 17:40:00 【Yangpengwei】
subject : Matrix zeroing Given a m x n Matrix , If an element is 0 , Set all elements of the row and column to 0 . Please use In situ Algorithm .
Ideas : First, set the row marked by the two arrays , Which column is promising 0 The elements of , Then traverse the matrix , Mark the qualified ones as 0 that will do .
code
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
vector<int> row(m), col(n);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (!matrix[i][j]) {
row[i] = col[j] = true;
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (row[i] || col[j]) {
matrix[i][j] = 0;
}
}
}
}
};边栏推荐
- How to view, modify, and delete SSH
- SQL游标(cursor)详细说明及内部循环使用示例
- 認識函數原創
- Introduction to several common functions of fiddler packet capturing (stop packet capturing, clear session window contents, filter requests, decode, set breakpoints...)
- Detailed explanation of shardingjdbc database and table
- Alibaba cloud image station supports IPv6!
- ftrace
- String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
- Application case of smart micro 32-bit MCU for server application cooling control
- bug记录:更新数据库时报错:Data truncation: Incorrect datetime value:
猜你喜欢

Article name

5、Embedding

Hangzhou AI developer meetup registration opens!

WinForm, crystal report making

《用户体验要素:以用户为中心的产品设计》笔记

How to win the "Olympic Games" in retail technology for jd.com, the learning tyrant of the "regular examination"?

论文《Deep Interest Evolution Network for Click-Through Rate Prediction》

文章名字

Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence

续2 asp.net core 路由程序基础使用演示0.2 默认控制器数据的获取到
随机推荐
Original error interface
TensorFlow2训练数据集的两种方式
String的split方法的使用
R language uses ggplot2 to visualize the density graph (curve) of specific data columns in dataframe data, and uses Xlim parameter to specify the range of X axis
The R language uses the tablestack function of epidisplay package to generate statistical analysis tables based on grouped variables (including descriptive statistical analysis, hypothesis test, diffe
《用户体验要素:以用户为中心的产品设计》笔记
新媒体运营素材网站分享,让你创作时事半功倍
(8) Goto keyword
The R language uses the plot function to visualize the data scatter chart, and uses font The axis parameter specifies that the font type of the axis scale label is italic
Are Huishang futures accounts reliable? Is the fund safe?
Figma从入门到放弃
R语言计算data.table在一个分组变量的值固定的情况下另外一个分组变量下指定数值变量的均值
Record the use of yolov5 to detect rotating targets
Application case of smart micro 32-bit MCU for server application cooling control
406. 根据身高重建队列
Sizepolicy policy in layout management
A variety of Qt development methods, which do you choose?
徽商期货开户可靠吗?资金安全吗?
(3) Golang - data type
Use GCC's PGO (profile guided optimization) to optimize the entire system