Skip to content

Commit c5c7774

Browse files
authored
Create 2125-number-of-laser-beams-in-a-bank.js
1 parent c68b096 commit c5c7774

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string[]} bank
3+
* @return {number}
4+
*/
5+
var numberOfBeams = function(bank) {
6+
const comb = (num1, num2) => num1 * num2
7+
const m = bank.length, n = bank[0].length
8+
if(m === 0 || n === 0) return 0
9+
let pre = 0, res = 0
10+
for(let j = 0; j < n; j++) {
11+
if(bank[0][j] === '1') pre++
12+
}
13+
for(let i = 1; i < m; i++) {
14+
let chk = 0, cur = bank[i]
15+
for(let j = 0; j < n; j++) {
16+
if(cur[j] === '1') chk++
17+
}
18+
if(chk) {
19+
res += comb(pre, chk)
20+
pre = chk
21+
}
22+
}
23+
return res
24+
};

0 commit comments

Comments
 (0)