simple cpp solution
Runtime: 152 ms, faster than 82.34% of C++ online submissions for Reconstruct a 2-Row Binary Matrix.\nMemory Usage: 60.5 MB, less than 100.00% of C++ online sub
Runtime: 152 ms, faster than 82.34% of C++ online submissions for Reconstruct a 2-Row Binary Matrix.\nMemory Usage: 60.5 MB, less than 100.00% of C++ online submissions for Reconstruct a 2-Row Binary Matrix.\n```\n    class Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        int i= 0, j, m = colsum.size();\n        int k = 0;\n        vector<vector<int>> output(2, (vector<int> (m, 0)));\n        while(k < m){\n            if(upper + lower < colsum[k]){\n                 vector<vector<int>> empty;\n                return empty;\n            }\n            if(colsum[k] == 2){\n                output[0][i] = 1;\n                output[1][i] = 1;\n                upper--;\n                lower--;\n            }else if(colsum[k] == 1){\n                if(upper >= lower){\n                    output[0][i] = 1;\n                    upper--;\n                }else{\n                    output[1][i] = 1;\n                    lower--;\n                }\n            }\n            k++;\n            i++;\n        }\n        if(upper != 0 || lower != 0){\n            vector<vector<int>> empty;\n            return empty;\n        }\n\n        return output;\n    }\n};
['C++']