forked from dscmsit/Problem-Solving-in-any-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrick_wall.cpp
More file actions
48 lines (47 loc) · 1 KB
/
brick_wall.cpp
File metadata and controls
48 lines (47 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Solution
{
public:
int leastBricks(vector<vector<int>> &wall)
{
vector<int> v;
int leng;
vector<vector<int>> ans;
for (auto it : wall)
{
int sum = 0;
for (auto i : it)
{
sum += i;
v.push_back(sum);
}
ans.push_back(v);
v.clear();
leng = sum;
}
for (auto it : ans)
{
for (auto i : it)
{
cout << i << " ";
}
}
unordered_map<int, int> m;
int maxx = 0;
for (auto it : ans)
{
for (auto i : it)
{
if (i == leng)
continue;
if (m.find(i) == m.end())
{
m[i] = 1;
}
else
m[i]++;
maxx = max(maxx, m[i]);
}
}
return wall.size() - maxx;
}
};