[LeetCode] 122. 买卖股票的最佳时机 II

class Solution {
    public int maxProfit(int[] prices) {
        int profit=0;
        for(int i=1;i<prices.length;i++){
            int tmp=prices[i]-prices[i-1];
            if(tmp>0) profit+=tmp;
        }
        return profit;
    }
}

 

posted @ 2020-06-18 18:13  doyi  阅读(107)  评论(0编辑  收藏  举报