Number of Laser Beams in a Bank LeetCode solution in Java

1
class Solution {
2
public int numberOfBeams(String[] bank) {
3
int ans = 0, pre = 0;
4
for (int i = 0; i < bank.length; i++) {
5
int n = 0;
6
for (int j = 0; j < bank[i].length(); j++) if (bank[i].charAt(j) == '1') n++;
7
if (n == 0) continue;
8
ans += pre * n;
9
;
10
pre = n;
11
}
12
return ans;
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0