Grind75
문제로

풀이

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution {
    public int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE;
        int profit = 0;
        for(int price : prices) {
            if(min > price) min = price;
            if(price - min > profit) profit = price - min;
        }

        return profit;
    }
}

image