当前位置:网站首页>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;
}
}
}
};
边栏推荐
- Conversion function and explicit
- Richview trvstyle liststyle list style (bullet number)
- [combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
- Go language web development series 27: Gin framework: using gin swagger to implement interface documents
- 项目协作的进度如何推进| 社区征文
- Go: send the get request and parse the return JSON (go1.16.4)
- JVM垃圾回收机
- Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
- Software testing is so hard to find, only outsourcing offers, should I go?
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
猜你喜欢

Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off

Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases

Uniapp tips - scrolling components

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

Qt学习20 Qt 中的标准对话框(中)

UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料

Go language unit test 3: go language uses gocovey library to do unit test

如何使用lxml判断网站公告是否更新

金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)

There is nothing new under the sun. Can the meta universe go higher?
随机推荐
项目协作的进度如何推进| 社区征文
Common network state detection and analysis tools
Go language unit test 3: go language uses gocovey library to do unit test
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Qt学习24 布局管理器(三)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Collection of mobile adaptation related articles
Summary of common error reporting problems and positioning methods of thrift
QT learning 24 layout manager (III)
Uniapp skills - dom display and hiding
Qt学习22 布局管理器(一)
MySQL 数据增删改查综合案例
1px problem of mobile terminal
GoLand 2021.2 configure go (go1.17.6)
Invalid Z-index problem
Ocean CMS vulnerability - search php
Use vscode to view hex or UTF-8 codes
Global event bus
Go 1.16.4: purpose of go mod tidy
【吉林大学】考研初试复试资料分享