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