C++ straightforward two-pass solution
The idea is simple, first fill all 2s. Then fill ones, and try to fill upper first. \n\n\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(i
The idea is simple, first fill all 2s. Then fill ones, and try to fill upper first. \n\n```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        vector<vector<int>> ret, empty;\n        \n        int n = colsum.size();\n        ret.resize(2);\n        ret[0].resize(n);\n        ret[1].resize(n);\n        for( int i=0; i<n; i++ )\n        {\n            if ( colsum[i] == 2 )\n            {\n                ret[0][i] = 1;\n                ret[1][i] = 1;\n                upper--;\n                lower--;\n            }\n            if ( upper < 0 || lower < 0 )\n                return empty;\n        }\n        \n        for( int i=0; i<n; i++ )\n        {\n            if ( colsum[i] == 1 )\n            {\n                if ( upper > 0 )\n                {\n                    ret[0][i] = 1;\n                    upper--;\n                }\n                else\n                {\n                    ret[1][i] = 1;\n                    lower --;\n                }\n            }\n            if ( upper < 0 || lower < 0 )\n                return empty;\n        }\n        \n        if ( upper!=0 || lower!=0 )\n            return empty;\n        else\n            return ret;\n    }\n};\n```\n
[]