leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0554.cpp (478B)
0 class Solution { 1 public: 2 int leastBricks(const vector<vector<int>> &wall) const { 3 const int n = size(wall); 4 unordered_map<int, int> count; 5 6 for (const auto &row : wall) { 7 long long crnt = 0; 8 for (int i = 0; i < size(row) - 1; i++) { 9 count[crnt += row[i]]++; 10 } 11 } 12 13 int res = 0; 14 for (const auto [_, v] : count) 15 res = max(res, v); 16 return n - res; 17 } 18 };