当前位置:网站首页>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;
}
}
}
};
边栏推荐
- 1px problem of mobile terminal
- Configure stylelint
- QT learning 17 dialog box and its types
- 信创产业现状、分析与预测
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- QT learning 19 standard dialog box in QT (top)
- Global event bus
- Ocean CMS vulnerability - search php
- Qt学习24 布局管理器(三)
- 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
猜你喜欢
可编程逻辑器件软件测试
JVM runtime data area
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
Qt学习21 Qt 中的标准对话框(下)
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
GoLand 2021.1.1: configure the multi line display of the tab of the open file
How to use lxml to judge whether the website announcement is updated
Qt学习20 Qt 中的标准对话框(中)
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
[email protected] Nanoparticles) | nano metal organic framework carry"/>
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
随机推荐
Qt学习20 Qt 中的标准对话框(中)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Record 405 questions about bank callback post request
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
[技術發展-24]:現有物聯網通信技術特點
Ocean CMS vulnerability - search php
QT learning 24 layout manager (III)
Configure stylelint
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
FPGA测试方法以Mentor工具为例
[Jilin University] information sharing of postgraduate entrance examination and re examination
如何使用lxml判断网站公告是否更新
Conversion function and explicit
Implementation of Muduo asynchronous logging
Implementation of Muduo accept connection, disconnection and sending data
Global event bus
JVM family - overview, program counter day1-1
QT learning 25 layout manager (4)
Spring cup eight school league