原题题目
代码实现(首刷自解)
class Solution {
public:vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {
int sum = 0,flag = 0;for(const auto& num:colsum) sum += num;vector<vector<int>> ret(2,vector<int>(colsum.size(),0)),temp;if(upper+lower != sum) return temp;for(int i=0;i<colsum.size();++i){
if(!colsum[i]) continue;flag = upper<lower;if(colsum[i] == 1){
ret[flag][i] = 1;if(flag) --lower;else --upper;}else{
ret[0][i] = ret[1][i] = 1;--lower;--upper;}if(lower<0 || upper<0) return temp;if(!lower && !upper) break;}if(lower>0 || upper>0) return temp;return ret;}
};