当前位置:网站首页>JS matrix zero
JS matrix zero
2022-07-03 14:06:00 【Cupid510】
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 .
Example 1:
Input :matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output :[[1,0,1],[0,0,0],[1,0,1]]
source : Power button (LeetCode)
/** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */
var setZeroes = function(matrix) {
let m = matrix.length
let n = matrix[0].length;
// Declaration line
const row = new Array(m).fill(false);
// Declaration column
const col = new Array(n).fill(false);
for (let i = 0; i < m; i++) {
for (let j = 0; j < n; j++) {
if (matrix[i][j] === 0) {
// Which lines 、 Which columns are 0
row[i] = col[j] = true;
}
}
}
for (let i = 0; i < m; i++) {
for (let j = 0; j < n; j++) {
if (row[i] || col[j]) {
matrix[i][j] = 0;
}
}
}
};
边栏推荐
- 消息订阅与发布
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- Example analysis of QT learning 18 login dialog box
- QT learning 17 dialog box and its types
- FPGA test method takes mentor tool as an example
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- Screenshot of the operation steps of upload labs level 4-level 9
- QT learning 25 layout manager (4)
- Redis:字符串类型数据的操作命令
- Selenium browser (1)
猜你喜欢

Halcon combined with C # to detect surface defects -- Halcon routine autobahn

JVM family - overview, program counter day1-1

Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock

Redis:字符串類型數據的操作命令

Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS

jvm-对象生命周期

Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?

Comprehensive case of MySQL data addition, deletion, modification and query

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material

Ocean CMS vulnerability - search php
随机推荐
FPGA测试方法以Mentor工具为例
QT learning 21 standard dialog box in QT (Part 2)
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
Comprehensive case of MySQL data addition, deletion, modification and query
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
Field problems in MySQL
Qt学习20 Qt 中的标准对话框(中)
SQL Injection (GET/Search)
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Message subscription and publishing
Common network state detection and analysis tools
Uniapp skills - dom display and hiding
Redis:Redis的数据结构、key的操作命令
Installation impression notes
Qt学习18 登录对话框实例分析
Programmable logic device software testing
1px problem of mobile terminal
page owner特性浅析
RocksDB LRUCache
Go: send the get request and parse the return JSON (go1.16.4)