class Solution { public int maxProfit(int[] prices) { int profit = 0; for (int i = 1; i < prices.length; i++) { int temp = prices[i] - prices[i - 1]; if (temp > 0) { profit += temp; } } return profit; } }
力扣122.买卖股票最佳时机II
于 2024-08-27 17:04:04 首次发布
class Solution { public int maxProfit(int[] prices) { int profit = 0; for (int i = 1; i < prices.length; i++) { int temp = prices[i] - prices[i - 1]; if (temp > 0) { profit += temp; } } return profit; } }