122. Best Time to Buy and Sell S

2016-12-17  本文已影响0人  夜皇雪
public class Solution {
    public int maxProfit(int[] prices) {
        if(prices.length==0) return 0;
        int max=0;
        for(int i=0;i<prices.length-1;i++){
            if(prices[i+1]>prices[i]) max+=prices[i+1]-prices[i];
        }
        return max;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读