We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 981adc7 + 883c4df commit 0483b96Copy full SHA for 0483b96
kotlin/121-Best-Time-to-Buy-and-Sell-Stocks.kt
@@ -0,0 +1,11 @@
1
+class Solution {
2
+ fun maxProfit(prices: IntArray): Int {
3
+ var buy = prices[0]
4
+ var maxDiff = 0
5
+ for (i in 1 until prices.size) {
6
+ buy = buy.coerceAtMost(prices[i])
7
+ maxDiff = maxDiff.coerceAtLeast(prices[i] - buy)
8
+ }
9
+ return maxDiff
10
11
+}
0 commit comments