leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0554.cpp (478B)


      1 class Solution {
      2   public:
      3     int leastBricks(const vector<vector<int>> &wall) const {
      4         const int n = size(wall);
      5         unordered_map<int, int> count;
      6 
      7         for (const auto &row : wall) {
      8             long long crnt = 0;
      9             for (int i = 0; i < size(row) - 1; i++) {
     10                 count[crnt += row[i]]++;
     11             }
     12         }
     13 
     14         int res = 0;
     15         for (const auto [_, v] : count)
     16             res = max(res, v);
     17         return n - res;
     18     }
     19 };