Number of Laser Beams in a Bank LeetCode solution in C++

1
class Solution {
2
public:
3
int numberOfBeams(vector<string> &bank) {
4
int rowLaserCount = 0, totalLaserCount = 0, prevCount = 0;
5
for (int i = 0; i < bank.size(); i++) {
6
rowLaserCount = 0;
7
for (char j : bank[i]) {
8
if (j == '1') rowLaserCount++;
9
}
10
totalLaserCount += (prevCount * rowLaserCount);
11
if (rowLaserCount) prevCount = rowLaserCount;
12
}
13
return totalLaserCount;
14
}
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0