https://leetcode.com/problems/brick-wall/description/
int leastBricks(vector<vector<int>>& wall) {
unordered_map<int,int> mp;
for(auto & v : wall) {
int w = 0;
for(int i=0; i<v.size()-1; i++) {
w += v[i];
mp[w]++;
}
}
int NW = wall.size(), res = NW;
for(auto &m: mp) {
int n = NW - m.second;
if(n<res) res = n;
}
return res;
}
No comments:
Post a Comment