| https://leetcode.com/problems/best-time-to-buy-and-sell-stock | Easy |
|---|
class Solution {
fun maxProfit(prices: IntArray): Int {
var mn = prices[0]
var best = 0
var i = 1
val n = prices.size
while (i < n) {
val p = prices[i]
if (p < mn) mn = p else {
val d = p - mn
if (d > best) best = d
}
i++
}
return best
}
}