8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 949acc5 commit 7c511ddCopy full SHA for 7c511dd
src/containerWithMostWater/containerWithMostWater.cpp
@@ -31,7 +31,16 @@ class Solution {
31
maxArea = area > maxArea ? area : maxArea;
32
// because the area is decided by the shorter edge
33
// so we increase the area is to increase the shorter edge
34
- height[left] < height[right] ? left++ : right-- ;
+ //height[left] < height[right] ? left++ : right-- ;
35
+ if (height[left] < height[right]) {
36
+ do {
37
+ left++;
38
+ } while (left < right && height[left-1] >= height[left]);
39
+ } else {
40
41
+ right--;
42
+ } while (right > left && height[right+1] >= height[right]);
43
+ }
44
}
45
46
return maxArea;
0 commit comments