当前位置:网站首页>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;
}
}
}
}
};边栏推荐
- First acquaintance with go language
- Codeforces Round #398 (Div. 2) D. Cartons of milk
- 字节飞书人力资源套件三面
- [CSP]202012-2期末预测之最佳阈值
- Tcp/ip family structure and protocol of tcp/ip series overview
- channel原创
- R语言使用plot函数可视化数据散点图,使用font.axis参数指定坐标轴刻度标签的字体类型为斜体字体(italic)
- R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouped variables and visual
- 三代DRI的变化
- Evolution and thinking of Taobao native R & D mode | DX R & D mode
猜你喜欢

Introduction to several common functions of fiddler packet capturing (stop packet capturing, clear session window contents, filter requests, decode, set breakpoints...)

借助SpotBugs将程序错误扼杀在摇篮中

多种Qt的开发方式,你选择哪种?

布局管理中的sizePolicy的策略问题

Learn the mitmproxy packet capturing tool from scratch

Gerrit+2 triggers Jenkins task

Qiushengchang: Practice of oppo commercial data system construction
Goframe gredis configuration management | comparison of configuration files and configuration methods

Installation and use of rolabelimg

《用户体验要素:以用户为中心的产品设计》笔记
随机推荐
Record the use of yolov5 to detect rotating targets
TensorFlow从网络读取数据
Understanding of binary search
The R language uses the tabpct function of the epidisplay package to generate a two-dimensional contingency table, and uses the mosaic diagram to visualize the contingency table (two-dimensional conti
php 实现无限极分类树(递归及其优化)
LCD参数解释及计算
Notes on user experience elements: user centered product design
多种Qt的开发方式,你选择哪种?
Arm64栈回溯
[CSP]202012-2期末预测之最佳阈值
WinForm, crystal report making
error接口原创
Risc-v ide mounriver studio v1.60 update point introduction
The R language uses the PDF function to save the visual image results to the PDF file, uses the PDF function to open the image device, uses the dev.off function to close the image device, and customiz
Introduction of one object one code tracing system
Installation and use of rolabelimg
消息队列实战之队列优先级
Dongfeng Yueda Kia, Tencent advertising and hero League mobile game professional league cooperate to build a new E-sports ecology
Use of split method of string
DRM 驱动 mmap 详解:(一)预备知识