Skip to content

Commit c24a66c

Browse files
authored
Create 2643-row-with-maximum-ones.js
1 parent 91b528d commit c24a66c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2643-row-with-maximum-ones.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[][]} mat
3+
* @return {number[]}
4+
*/
5+
var rowAndMaximumOnes = function(mat) {
6+
const arr= []
7+
const m = mat.length, n = mat[0].length
8+
let ma = 0
9+
for(let i = 0; i < m; i++) {
10+
let cnt = 0
11+
for(let j = 0; j < n; j++) {
12+
if(mat[i][j] === 1) cnt++
13+
}
14+
arr[i] = cnt
15+
ma = Math.max(ma, cnt)
16+
}
17+
18+
for(let i = 0; i < m; i++) {
19+
if(arr[i] === ma) return [i, ma]
20+
}
21+
};

0 commit comments

Comments
 (0)