当前位置:网站首页>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
边栏推荐
- 同心向前,Google Play 十周年啦!
- Leetcode 2341. How many pairs can an array form
- Introduction to routing strategy
- Let's move forward together, the 10th anniversary of Google play!
- 伦敦银开盘时间知多少
- qt 设置图标
- Lua进阶
- BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (
- Knowledge of two-dimensional array
- 字节月薪28K,分享一波我的自动化测试经验....
猜你喜欢

Lua advanced

Matlab 44 animation gradient drawing programs

Codeforces暑期训练周报(7.14~7.20)
![[C language] file operation](/img/6e/b8f3466ca0a5f7424afcab561124af.png)
[C language] file operation

Principle of logistic regression

Article reproduction: super resolution network fsrcnn

字节月薪28K,分享一波我的自动化测试经验....

在一个字符串里面统计给定字符串的个数

Redefine analysis - release of eventbridge real-time event analysis platform

现货白银如何计算盈亏
随机推荐
面试题 01.06. 字符串压缩
If you are still using WiFi, you will be out: li-fi is better!!!
How to make digital retail undertake the development task of the era of traffic and retention may be the key
Principle of logistic regression
Standing at the crossroads of digital retail transformation, we need to look at it from a new perspective
MATLAB 44种动漫渐变色绘图程序
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!
String
Lua advanced
Leetcode 2351. the first letter that appears twice
Introduction to QT drawing system
20 bad habits of bad programmers
C language main function transfer parameters
Matlab 44 animation gradient drawing programs
Huami technology "Huangshan No.2" release: AI performance is improved by 7 times, and power consumption is reduced by 50%!
Opengauss active / standby architecture works with keeplive
From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.
Software test interview question: what are the performance test indicators?
Software testing interview question: where do your performance testing requirements come from?
新安装的pip3,使用出现No module named ‘lsb_release‘的问题