Today I Learned

[프로그래머스] 스택/큐Level 2. 주식가격(JAVA) 본문

알고리즘 & 코딩테스트

[프로그래머스] 스택/큐Level 2. 주식가격(JAVA)

하이라이터 2021. 1. 28. 02:53
728x90

비교 대상이 하나씩 줄어들어서 큐 문제인건가?

간단한 문제이므로 설명은 생략

 

코드

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++) {
                answer[i]++;
                if (prices[i] > prices[j])
                    break;
            }
        }
        return answer;
    }
}

 

결과

 

728x90
Comments