LeetCode - 122. Best Time to Buy and Sell Stock II
Задача для самостоятельной работы.
Не смотри видео ниже, пока не попробуешь сам.
Код на языке Swift
func maxProfit(_ prices: [Int]) -> Int {
var profit = 0
for i in 1..<prices.count {
let diff = prices[i] - prices[i-1]
if diff > 0 {
profit += diff
}
}
return profit
}
course_intro
leetcode