int maxProfit(int* arr,int len){
if(arr == NULL || len <= 0)
return -1;
int profit = 0,maxProfit = 0;
for(int i = 1;i < len;i++){
if(profit < 0)
profit = 0;
profit += (arr[i]-arr[i-1]);
if(profit > maxProfit)
maxProfit = profit;
}
return maxProfit;
}
类似连续子数组的最大和问题。