Posted on

Description

Submission

class Solution {
    typedef long long ll;
public:
    int leastBricks(vector<vector<int>>& wall) {
        int n = wall.size();
        
        unordered_map<int, int> count;

        for(int i = 0; i < n; ++i) {
            ll sum = 0;
            for(int j = 0; j < wall[i].size() - 1; ++j) {
                sum += wall[i][j];
                ++count[sum];
            }
        }

        int m = 0;
        for(auto it = count.begin(); it != count.end(); ++it) {
            m = max(it->second, m);
        }
        
        return (n - m);
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *