avoid unnecessary calculations to speed up

This commit is contained in:
Jak Wings 2014-11-28 00:35:08 +08:00 committed by Hao Chen
parent 949acc5421
commit 7c511ddfe7

View File

@ -31,7 +31,16 @@ public:
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;