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; } }
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; } }
相关推荐