Open youngyangyang04 opened 3 months ago
class Solution {
public int maxProfit(int[] prices) {
int total = 0;
for (int i = 1; i < prices.length; i++) {
int money = prices[i] - prices[i - 1];
if(money > 0) total += money;
}
return total;
}
}
https://www.programmercarl.com/0122.%E4%B9%B0%E5%8D%96%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E6%97%B6%E6%9C%BAII.html