LeetCode/java/best-time-to-buy-and-sell-stock-ii.java

13 lines
247 B
Java

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