Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 660 Bytes

18.md

File metadata and controls

26 lines (21 loc) · 660 Bytes
 int calc(const std::string& s) {
        int count = 0;
        for (char c : s)
            count += c - '0';

        return count;
    }
    int numberOfBeams(vector<string>& bank) {
          int prevRowCount = 0;
        int total = 0;

        for (const std::string& row : bank) {
            int curRowCount = calc(row);
            if (curRowCount == 0)
                continue;

            total += curRowCount * prevRowCount;
            prevRowCount = curRowCount;
        }
        return total;
    }