Beats 100.00% of users with Python in runtime and memory
Approach\nUsing dynamic programming to calculate the height of each column, representing the number of consecutive ones ending at that column.\nThen sorting the
# Approach\nUsing dynamic programming to calculate the height of each column, representing the number of consecutive ones ending at that column.\nThen sorting the columns based on their height.\nThen, calculating the maximum area of the submatrix containing only ones.\n\n# Complexity\n- Time complexity:\nO(m * n * log(n))\n\n- Space complexity:\nO(n) <--array storing the heights\n\n# Code\n```\nclass Solution(object):\n    def largestSubmatrix(self, matrix):\n        """\n        :type matrix: List[List[int]]\n        :rtype: int\n        """\n        if not matrix or not matrix[0]:\n            return 0\n\n        m, n = len(matrix), len(matrix[0])\n        height = [0] * n\n        max_area = 0\n\n        for i in range(m):\n            for j in range(n):\n                height[j] = height[j] + 1 if matrix[i][j] == 1 else 0\n\n            sorted_height = sorted(height)\n            for j in range(n):\n                max_area = max(max_area, sorted_height[j] * (n - j))\n\n        return max_area\n\n```
['Python']