LeetCode - 121. Best Time to Buy and Sell Stock
Код на языке Swift
func maxProfit(_ prices: [Int]) -> Int {
var minPrice = Int.max
var maxProfit = 0
for price in prices {
if price < minPrice {
minPrice = price
}
let profit = price - minPrice
if profit > maxProfit {
maxProfit = profit
}
}
return maxProfit
}
course_intro
leetcode