题号:11 标题:Container With Most Water 难度:Medium
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
Notice that you may not slant the container.
我的程序码
int maxArea(int* height, int heightSize){
int area=0,area_temp;
int r,l,temp;
l=0; r=heightSize-1;
while(r>l){
printf("%d,%d\n",r,l);
if(height[r]>height[l]){
area_temp = height[l] * (r-l);
temp = height[r];
l++;
while(temp> height[l]){
if(r>l){
break;
}
l++;
}
}else{
area_temp = height[r] * (r-l);
temp = height[l];
r--;
while(temp> height[r]){
if(r>l){
break;
}
r--;
}
}
if(area_temp>area){
area = area_temp;
}
}
return area;
}
DAY13心得
昨天要感谢台积电辣妹,今天要感谢男友给我解题提示,不然我一直超时,写到现在觉得最难的还是特殊CASE跟时间复杂度,然後我真的要去睡了
>>: 【Day14】:STM32辗压Arduino的功能—TIM(上)
今天要来介绍广播接收程序,先从Broadcast receiver的运作机制,它的运作机制包含:送出...
ES6:Promise Promise:代表一个即将成功或失败的非同步操作 会有这几状态: 搁置 (...
Git 是开发者们最常接触到的工具之一,大部分的专案都使用它作为版本控制的工具。使用者可以直接用 g...
年轻人不要看到标题就兴奋好吗? 以目前前後端分离的趋势,前端及後端工程师势必会由两个人以上来担任,那...
不管是数位还是手写,各有各种的好处,端看每个人的需求。来看数位及传统载体的优劣势:手写的最大好处是在...