문제로

풀이

 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
    }
}