当前位置:网站首页>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;
}
}
}
}
};边栏推荐
- Gerrit+2 triggers Jenkins task
- Are Huishang futures accounts reliable? Is the fund safe?
- 电控学习 第二周
- Cesium抛物线方程
- 淘宝Native研发模式的演进与思考 | DX研发模式
- R语言使用epiDisplay包的tabpct函数生成二维列联表并使用马赛克图可视化列联表(二维列联表、边际频数、以及按行、按列的比例)、自定义设置cex.axis参数改变轴标签数值的大小
- 32-bit MCU mm32f0040 with smart micro high performance M0 kernel
- 内核中断整体流程图
- error接口原创
- 118. 杨辉三角(动态规划)
猜你喜欢

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

First acquaintance with go language

"Upgrade strategy" of two new committers

Tensorflow prompts typeerror: unsupported operand type (s) for *: 'float' and 'nonetype‘

Kill program errors in the cradle with spotbugs

消息队列存储消息数据的 MySQL 表格

Detailed explanation of shardingjdbc database and table

Use GCC's PGO (profile guided optimization) to optimize the entire system

Arm64 Stack backtrack

Sizepolicy policy in layout management
随机推荐
R语言使用epiDisplay包的pyramid函数可视化金字塔图、基于已有的汇总数据(表格数据)可视化金字塔图
C# 业务流水号规则生成组件
Evolution and thinking of Taobao native R & D mode | DX R & D mode
Arm64 Stack backtrack
channel原创
Arm64栈回溯
Cesium抛物线方程
Sizepolicy policy in layout management
续2 asp.net core 路由程序基础使用演示0.2 默认控制器数据的获取到
Crazy temporary products: super low price, big scuffle and new hope
Is it cost-effective to apply for Huagui sweet home term life insurance? What are the advantages of this product?
Goframe gredis configuration management | comparison of configuration files and configuration methods
5-5 configuring MySQL replication log point based replication
山东大学软件学院项目实训-创新实训-山大软院网络攻防靶场实验平台(二十五)-项目个人总结
566. 重塑矩阵
Deep interest evolution network for click through rate prediction
Implementation of asynchronous query of Flink dimension table and troubleshooting
数组按指定顺序排序
(8) Goto keyword
Fiddler抓包几种常用功能介绍(停止抓包、清空会话窗内容、过滤请求、解码、设置断点......)