leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1727.cpp (640B)
0 class Solution { 1 public: 2 int largestSubmatrix(vector<vector<int>> &matrix) { 3 const int n = matrix.size(), m = matrix[0].size(); 4 vector<int> height(m, 0); 5 int ans = 0; 6 7 for (int i = 0; i < n; i++) { 8 for (int j = 0; j < m; j++) { 9 if (matrix[i][j] == 0) 10 height[j] = 0; 11 else 12 height[j] += 1; 13 } 14 15 vector<int> order = height; 16 sort(begin(order), end(order)); 17 18 for (int j = 0; j < m; j++) 19 ans = max(ans, order[j] * (m - j)); 20 } 21 return ans; 22 } 23 };