122. Best Time to Buy and Sell Stock II
Last updated
Last updated
func maxProfit(prices []int) int {
profit := 0
min := prices[0]
for i := 1; i < len(prices); i++ {
if prices[i] < min {
min = prices[i]
} else {
profit += prices[i] - min
min = prices[i]
}
}
return profit
}