fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. int largestRectangleArea(vector<int>& heights) {
  7. return daq(heights, 0, heights.size() - 1);
  8. }
  9.  
  10. int daq(vector<int>& heights, int left, int right) {
  11. if (left == right) {
  12. return heights[left];
  13. } else if (left > right) {
  14. return 0;
  15. }
  16.  
  17. int res = -1;
  18. int mid = (left + right) / 2;
  19. int tempLeft = mid, tempRight = mid;
  20. int mx = -1, minHeight = INT_MAX;
  21.  
  22. while (left <= tempLeft && tempRight <= right) {
  23. minHeight = min(minHeight, heights[tempLeft]);
  24. minHeight = min(minHeight, heights[tempRight]);
  25. mx = max(mx, (tempRight - tempLeft + 1) * minHeight);
  26. if (left < tempLeft && tempRight < right) {
  27. if (heights[tempLeft - 1] > heights[tempRight + 1]) {
  28. tempLeft--;
  29. } else {
  30. tempRight++;
  31. }
  32. } else if (left == tempLeft) {
  33. tempRight++;
  34. } else {
  35. tempLeft--;
  36. }
  37. }
  38.  
  39. res = max(res, mx);
  40. res = max(res, daq(heights, left, mid));
  41. res = max(res, daq(heights, mid + 1, right));
  42. return res;
  43. }
  44. };
  45.  
  46. int main() {
  47. // your code goes here
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:30: error: ‘vector’ has not been declared
     int largestRectangleArea(vector<int>& heights) {
                              ^~~~~~
prog.cpp:6:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     int largestRectangleArea(vector<int>& heights) {
                                    ^
prog.cpp:10:13: error: ‘vector’ has not been declared
     int daq(vector<int>& heights, int left, int right) {
             ^~~~~~
prog.cpp:10:19: error: expected ‘,’ or ‘...’ before ‘<’ token
     int daq(vector<int>& heights, int left, int right) {
                   ^
prog.cpp: In member function ‘int Solution::largestRectangleArea(int)’:
prog.cpp:7:20: error: ‘heights’ was not declared in this scope
         return daq(heights, 0, heights.size() - 1);
                    ^~~~~~~
prog.cpp: In member function ‘int Solution::daq(int)’:
prog.cpp:12:20: error: ‘heights’ was not declared in this scope
             return heights[left];
                    ^~~~~~~
prog.cpp:18:25: error: invalid operands of types ‘std::ios_base&(std::ios_base&)’ and ‘std::ios_base&(std::ios_base&)’ to binary ‘operator+’
         int mid = (left + right) / 2;
                    ~~~~~^~~~~~~
prog.cpp:20:34: error: ‘INT_MAX’ was not declared in this scope
         int mx = -1, minHeight = INT_MAX;
                                  ^~~~~~~
prog.cpp:22:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         while (left <= tempLeft && tempRight <= right) {
                        ^~~~~~~~
prog.cpp:22:49: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         while (left <= tempLeft && tempRight <= right) {
                                                 ^~~~~
prog.cpp:23:40: error: ‘heights’ was not declared in this scope
             minHeight = min(minHeight, heights[tempLeft]);
                                        ^~~~~~~
prog.cpp:26:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
             if (left < tempLeft && tempRight < right) {
                        ^~~~~~~~
prog.cpp:26:48: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
             if (left < tempLeft && tempRight < right) {
                                                ^~~~~
prog.cpp:32:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
             } else if (left == tempLeft) {
                                ^~~~~~~~
prog.cpp:40:28: error: ‘heights’ was not declared in this scope
         res = max(res, daq(heights, left, mid));
                            ^~~~~~~
stdout
Standard output is empty