低买高卖,可以多次进行,求最大的利润
class Solution {
public int maxProfit(int[] prices) {
int profit = 0,i=0;
while(i<prices.length){
while(i<prices.length-1 && prices[i+1]<=prices[i]) i++;
int min = prices[i++];
while(i<prices.length-1 && prices[i+1]>=prices[i]) i++;
profit += i<prices.length?(prices[i++] - min):0;
}
return profit;
}
}