We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4fdf36f commit 9e2277fCopy full SHA for 9e2277f
brick-wall.cpp
@@ -0,0 +1,31 @@
1
+//Runtime: 46 ms
2
+class Solution {
3
+public:
4
+ int leastBricks(vector<vector<int>>& wall) {
5
+ map<int, int> mp;
6
+ int size = 0;
7
+ int minn = INT_MAX;
8
+ int maxn = INT_MIN;
9
+ for (auto vec : wall) {
10
+ int c = 0;
11
+ for (int i : vec) {
12
+ c += i;
13
+ mp[c]++;
14
+ minn = min(minn, i);
15
+ maxn = max(maxn, i);
16
+ }
17
+ size = c;
18
19
+ int res = INT_MAX;
20
+ mp[size] = -INT_MIN;
21
+ int ht = wall.size();
22
+
23
+ for (auto &m : mp) {
24
+ if (m.first != size)
25
+ res = min(res, ht - m.second);
26
27
+ if (maxn == minn && res == INT_MAX)
28
+ return ht;
29
+ return res;
30
31
+};
0 commit comments