122. Best Time to Buy and Sell Stock II 📈💰
Last updated
Last updated
prices = [1,2,3,4,5]4prices = [7,6,4,3,1]0class Solution {
public int maxProfit(int[] prices) {
int profit = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i] > prices[i - 1]) {
profit += prices[i] - prices[i - 1];
}
}
return profit;
}
}