2125.cpp (322B)
1 class Solution { 2 public: 3 int numberOfBeams(const vector<string>& bank) const { 4 int res = 0, prev = 0; 5 for(const auto& floor: bank) { 6 int cnt = 0; 7 for(const char c: floor) cnt += c == '1'; 8 if(cnt) res += cnt * prev, prev = cnt; 9 } 10 return res; 11 } 12 };