Fork me on GitHub

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

class Solution {
public int maxProfit(int[] prices) {
		 int maxPro = 0, tmp = 0;
	        for (int i = 1; i < prices.length; ++i) {
	            tmp = prices[i] - prices[i-1];
	            if (tmp > 0)
	                maxPro += tmp;
	        }
	        return maxPro;
	    }
}
posted @ 2019-08-04 15:02  cznczai  阅读(72)  评论(0编辑  收藏  举报