mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-09-20 01:56:57 +02:00
22 lines
476 B
C++
22 lines
476 B
C++
|
#include <algorithm>
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
|
||
|
class Solution {
|
||
|
public:
|
||
|
int numberOfBeams(const std::vector<std::string>& bank) {
|
||
|
int beams = 0;
|
||
|
|
||
|
int last_row = 0;
|
||
|
for (const auto& row : bank) {
|
||
|
if (auto current_row = std::count(row.begin(), row.end(), '1'); current_row != 0) {
|
||
|
beams += last_row * current_row;
|
||
|
last_row = current_row;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return beams;
|
||
|
}
|
||
|
};
|
||
|
|