当前位置:网站首页>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;
}
}
}
};
边栏推荐
- Go 1.16.4: purpose of go mod tidy
- 核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
- Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
- Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
- 解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- 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
- 信创产业现状、分析与预测
- Qt学习18 登录对话框实例分析
- selenium 浏览器(1)
- Installation impression notes
猜你喜欢

使用vscode查看Hex或UTF-8编码

可编程逻辑器件软件测试

Go language web development series 30: gin: grouping by version for routing

Qt学习18 登录对话框实例分析
![[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered

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

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

jvm-运行时数据区

Ocean CMS vulnerability - search php

SQL Injection (GET/Search)
随机推荐
Implementation of Muduo accept connection, disconnection and sending data
C language standard IO function sorting
[how to earn a million passive income]
JVM class loading
Multi person collaborative data annotation based on Baidu brain easydata from scratch
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
[acnoi2022] guess numbers
Function calling convention
Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
PhpMyAdmin stage file contains analysis traceability
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
[Jilin University] information sharing of postgraduate entrance examination and re examination
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
How to use lxml to judge whether the website announcement is updated
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
[技术发展-24]:现有物联网通信技术特点
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
Use and design of Muduo buffer class
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
Spring cup eight school league