1
class Solution {
2
public:
3
vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int> &colsum) {
4
vector<int> u, l;
5
vector<vector<int>> ans;
6

7
for (int i : colsum) {
8
if (i == 2) {
9
u.push_back(1);
10
l.push_back(1);
11
upper--;
12
lower--;
13
} else if (i == 0)
14
u.push_back(0), l.push_back(0);
15

16
else if (i == 1) {
17
if (upper >= lower) {
18
u.push_back(1);
19
l.push_back(0);
20
upper--;
21
} else {
22
u.push_back(0);
23
l.push_back(1);
24
lower--;
25
}
26
}
27
}
28
if (upper == 0 && lower == 0) {
29
ans.push_back(u);
30
ans.push_back(l);
31
}
32
return ans;
33
}
34
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0