LeetCode: Set Matrix Zeroes Solution
1/**2 * @param {number[][]} matrix3 * @return {void} Do not return anything, modify matrix in-place instead.4 */5var setZeroes = function (matrix) {6 const N = matrix.length7 const M = matrix[0].length8 let setI = new Set()9 let setJ = new Set()1011 for (let i = 0; i < N; i++) {12 for (let j = 0; j < M; j++) {13 if (matrix[i][j] === 0) {14 setI.add(i)15 setJ.add(j)16 }17 }18 }1920 for (let i = 0; i < N; i++) {21 for (let j = 0; j < M; j++) {22 if (setI.has(i) || setJ.has(j)) {23 matrix[i][j] = 024 }25 }26 }2728 return matrix29}
Comments
Loading comments...
Tags
leetcode
array
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
LeetCode: Group Anagrams
Feb 8, 2021
Previous Post
LeetCode: Merge Sorted Array
Feb 8, 2021