We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c68b096 commit c5c7774Copy full SHA for c5c7774
2125-number-of-laser-beams-in-a-bank.js
@@ -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
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