rocksc30 / LeetCode

用于力扣刷题打卡
2 stars 0 forks source link

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

Open rocksc30 opened 1 year ago

rocksc30 commented 1 year ago
class Solution {
    public int maxProfit(int[] prices) {
        int ans = 0;
        for (int i = 1; i < prices.length; i++){
            ans += Math.max(prices[i] - prices[i - 1], 0);
        }
        return ans;
    }
}