Skip to content

Commit 5e2f011

Browse files
authored
Update 861-score-after-flipping-matrix.js
1 parent 907481d commit 5e2f011

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

861-score-after-flipping-matrix.js

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

0 commit comments

Comments
 (0)