티스토리 뷰





반응형

Java

class Solution {
    public int[] solution(int[] prices) {
        int[] answer = new int[prices.length];
        
        for(int i=0; i<prices.length; i++){
            for(int j=i+1; j<prices.length; j++){
                if(prices[i] > prices[j]){
                    // prices[i] = 3, prices[j] = 2 일 경우
                    // 3에서 2로 가격이 떨어졌지만 1초뒤에 떨어진걸로 간주하여 이것도 1은 증가해준다.
                    answer[i]++;
                    break;
                }else{
                    answer[i]++;
                }
            }
        }
        return answer;
    }
}

이건 문제가 이해하기가 더 어렵네;

반응형
댓글
반응형
최근에 달린 댓글
글 보관함
Total
Today
Yesterday
최근에 올라온 글
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31