문제로
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| class Solution {
fun maxProfit(prices: IntArray): Int {
var minPrice = Int.MAX_VALUE
var maxProfit = 0;
for(price in prices) {
if(minPrice > price) minPrice = price
else {
maxProfit = max(maxProfit, price - minPrice)
}
}
return maxProfit
}
}
|
이 문제는 Grind 75에서도 다뤘다: Grind 75 - Best Time to Buy and Sell Stock