题目:
题解:
class Solution { public int maxProfit(int[] prices) { int ans = 0; int n = prices.length; for (int i = 1; i < n; ++i) { ans += Math.max(0, prices[i] - prices[i - 1]); } return ans; } }
题目:
题解:
class Solution { public int maxProfit(int[] prices) { int ans = 0; int n = prices.length; for (int i = 1; i < n; ++i) { ans += Math.max(0, prices[i] - prices[i - 1]); } return ans; } }
转载请注明来自码农世界,本文标题:《Java | Leetcode Java题解之第122题买卖股票的最佳时机II》
还没有评论,来说两句吧...