Skip to content

Commit

Permalink
avoid unnecessary calculations to speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
jakwings authored and haoel committed Dec 30, 2014
1 parent 949acc5 commit 7c511dd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/containerWithMostWater/containerWithMostWater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ class Solution {
maxArea = area > maxArea ? area : maxArea;
// because the area is decided by the shorter edge
// so we increase the area is to increase the shorter edge
height[left] < height[right] ? left++ : right-- ;
//height[left] < height[right] ? left++ : right-- ;
if (height[left] < height[right]) {
do {
left++;
} while (left < right && height[left-1] >= height[left]);
} else {
do {
right--;
} while (right > left && height[right+1] >= height[right]);
}
}

return maxArea;
Expand Down

0 comments on commit 7c511dd

Please sign in to comment.