当前位置:网站首页>Interview question 01.08. Zero matrix
Interview question 01.08. Zero matrix
2022-07-28 01:40:00 【Welcome to the confrontation Road】
Subject requirements :
Write an algorithm , if M × N An element in the matrix is 0, The row and column in which it is located are cleared .
Example 1:
Input :
[
[1,1,1],
[1,0,1],
[1,1,1]
]
Output :
[
[1,0,1],
[0,0,0],
[1,0,1]
]
Example 2:
Input :
[
[0,1,2,0],
[3,4,5,2],
[1,3,1,5]
]
Output :
[
[0,0,0,0],
[0,4,5,0],
[0,3,1,0]
]
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int m, n;
m = matrix.size();
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] == 0)
{
row[i]=1;
col[j]=1;
}
}
}
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(row[i]||col[j])
matrix[i][j] = 0;
}
}
}
};
Experience :
Create one dimension vector:
vector nums;// Do not specify length
vector nums(n); // The specified length is n
https://blog.csdn.net/cmy1130/article/details/88971585
边栏推荐
- My rich second generation friend
- 华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘
- Develop plug-ins for the recording function of flutter
- Thoroughly understand kubernetes scheduling framework and plug-ins
- 8000字讲透OBSA原理与应用实践
- Codeforces暑期训练周报(7.14~7.20)
- Oracle Rac 集群文件目录迁移
- 迅为i.MX6ULL开发板Qt系统移植-交叉编译Qt代码
- Leetcode 2341. How many pairs can an array form
- Cap principle of [distributed development]
猜你喜欢

Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium

docker 本地搭建mysql主从

股票问题5连

登录功能实现

ICML2022 | 在线决策Transformer

Byte monthly salary 28K, share a wave of my automation testing experience

Lua advanced

HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新

Icml2022 | online decision transformer

华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘
随机推荐
Redefine analysis - release of eventbridge real-time event analysis platform
The total investment is nearly 1.6 billion yuan! Qianzhao optoelectronics VCSEL and high-end LED chip projects officially started
Matlab 44 animation gradient drawing programs
2.2综合应用题-顺序表
Cesium add inundation analysis measurement area
3000 words and 11 pictures hard core popular science: what is edge computing? What are the connections and differences with cloud computing?
BYD semiconductor completed the a+ round financing of 800million yuan: 30 well-known investment institutions entered the market, with a valuation of 10.2 billion yuan!
Cross domain requests in nodejs
BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)
内容bypass分享
LeetCode 2351. 第一个出现两次的字母
Codeforces暑期训练周报(7.21~7.27)
Knowledge of two-dimensional array
梳理 SQL 性能优化,收藏经典!
同心向前,Google Play 十周年啦!
How to make digital retail undertake the development task of the era of traffic and retention may be the key
ICML2022 | 在线决策Transformer
Login function implementation
Shutter -- password login registration interface
QT setting Icon