You can do that on ONE LINE C++ OR others 19ms


  • 0
    C
    class Solution {
    public:
        int maxArea(vector<int>& height) {
            int result=0,tempResult=0,left=0;
            int right=height.size()-1;
            while(left<right){
      //u should notice that the position of  ++ and --
     //你应该注意++ 和-- 的位置
            tempResult=height[left]<height[right]?height[left]*(right-(left++)):height[right]*((right--)-left);
        
            result=result>tempResult?result:tempResult;
            }
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.