public class Solution {
public int maxArea(int[] height){
if(height == null) return 0;
int start = 0, end = height.length - 1;
int maxArea = (end - start) * Math.min(height[start],height[end]);
while(start + 1 < end){
if(height[start] < height[end]) start ++;// You can understand this in a general way; find out the smaller one, and then replace it by its next one for try
else end --;
int tempArea = (end - start) * Math.min(height[start],height[end]);
maxArea = Math.max(maxArea,tempArea);
}
return maxArea;
}
}
Hello, welcome to Yizhe's Blog. I am Yizhe Liu, graduated from University of Arizona, with Master degree, major in Electrical and Computer Engineering. Actually, I am software guy. In my blog, many posts are about the Leetcode questions. I will post my ideas and implementations, which are accepted by Leetcode. If you have different opinions, please leave comment. I am happy to discuss with you. So lets start rocking them!!!
No comments:
Post a Comment