Skip to content

Commit 9ef0be4

Browse files
committed
1 parent 6ed8738 commit 9ef0be4

File tree

1 file changed

+13
-0
lines changed
  • src/main/kotlin/leetcode/best-time-to-buy-and-sell-stock

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package leetcode.`best-time-to-buy-and-sell-stock`
2+
3+
class Solution {
4+
fun maxProfit(prices: IntArray): Int {
5+
var money = 0
6+
var max = 0
7+
for (i in prices.lastIndex downTo 0){
8+
max = Math.max(max, prices[i])
9+
money = Math.max(money, max - prices[i])
10+
}
11+
return money
12+
}
13+
}

0 commit comments

Comments
 (0)