message: Update maximal-rectangle.cpp
diff: @@ -9,37 +9,29 @@ public:
  return 0;
  }
  - int res = 0;
  - vector<int> height(matrix[0].size(), 0);
  + int result = 0;
  + vector<int> heights(matrix[0].size(), 0);
  for (int i = 0; i < matrix.size(); ++i) {
  for (int j = 0; j < matrix[0].size(); ++j) {
  - height[j] = matrix[i][j] == '1' ? height[j] + 1 : 0;
  + heights[j] = matrix[i][j] == '1' ? heights[j] + 1 : 0;
  }
  - res = max(res, largestRectangleArea(height));
  + result = max(result, largestRectangleArea(heights));
  }
  -
  - return res;
  + return result;
  }
  private:
  - int largestRectangleArea(const vector<int> &height) {
  - stack<int> increasing_height;
  - int max_area = 0;
  -
  - for (int i = 0; i <= height.size();) {
  - if (increasing_height.empty() ||
  - (i < height.size() && height[i] > height[increasing_height.top()])) {
  - increasing_height.emplace(i);
  - ++i;
  - } else {
  - auto h = height[increasing_height.top()];
  - increasing_height.pop();
  - auto left = increasing_height.empty() ? -1 : increasing_height.top();
  - max_area = max(max_area, h * (i - left - 1));
  + int largestRectangleArea(const vector<int>& heights) {
  + vector<int> stk = {-1};
  + int res = 0;
  + for (int i = 0; i <= size(heights); ++i) {
  + while (stk.back() != -1 && (i == size(heights) || heights[stk.back()] >= heights[i])) {
  + int last = stk.back(); stk.pop_back();
  + res = max(res, heights[last] * ((i - 1) - stk.back()));
  }
  + stk.emplace_back(i);
  }
  -
  - return max_area;
  + return res;
  }
  };
  