C++ | Easy and Clean code | Simple logic
Intuition\nIf number of 2\'s in colsum is represented by cnt, that means upper and lower must be equal to or greater than cnt.\n\n# Approach\n Describe your app
# Intuition\nIf number of 2\'s in colsum is represented by cnt, that means upper and lower must be equal to or greater than cnt.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        vector<vector<int>> ans;\n        int cnt = 0;\n\n        int temp = 0;\n        for(int i=0; i<colsum.size(); i++){\n            temp += colsum[i];\n            if(colsum[i] == 2) cnt++;\n        }\n\n        if(temp != upper + lower) return ans;\n        if(lower < cnt || upper < cnt) return ans;\n\n        int n = colsum.size();\n        vector<int> a(n, 0);\n        vector<int> b(n, 0);\n\n        for(int i=0; i<colsum.size(); i++){\n            if(colsum[i] == 1){\n                if(upper >= lower){\n                    a[i] = 1;\n                    upper--;\n                }\n                else{\n                    b[i] = 1;\n                    lower--;\n                }\n            }\n            if(colsum[i] == 2){\n                a[i] = 1;\n                b[i] = 1;\n                upper--;\n                lower--;\n            }\n        }\n\n        ans.push_back(a);\n        ans.push_back(b);\n        return ans;\n    }\n};\n```
['C++']