Python: find indexes of 2 and 1 (596 - 604 ms / ~ 100%)
The idea is pretty straight forward. Find out all indexes of 2 in colsum and then distribute 1 to the rest of columns.\npython\ndef reconstructMatrix(self, uppe
The idea is pretty straight forward. Find out all indexes of `2` in `colsum` and then distribute `1` to the rest of columns.\n```python\ndef reconstructMatrix(self, upper, lower, colsum):\n        # check sum\n        if upper+lower != sum(colsum): \n            return []\n        \n        n = len(colsum)\n        ret = [[0]*n for _ in range(2)]\n        \n        ind = collections.defaultdict(list)\n        for i, x in enumerate(colsum):\n            ind[x].append(i)\n        \n        # simple inference\n        if lower < len(ind[2]) or upper < len(ind[2]):\n            return []\n            \n        # distribute numbers\n        u = upper\n        for i in ind[2]:\n            ret[0][i] = ret[1][i] = 1\n            u -= 1\n            \n        for i in ind[1]:\n            if u:\n                ret[0][i] = 1\n                u -= 1\n            else:\n                ret[1][i] = 1\n        \n        return ret\n```
['Python']