알고리즘 풀이/프로그래머스

[프로그래머스][Java] 주식가격

배게 2019. 3. 13. 18:09
728x90



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class Solution {
    public int[] solution(int[] prices) {
        int len = prices.length;
        int[] answer = new int[len];


        for(int i = 0; i <len -1; i++){
            for(int j = i+1; j< len; j++){
                if(prices[i] > prices[j] || j == len - 1){
                    answer[i] = j-i;
                    break;
                }
            }
        }
        answer[len - 1] = 0;

        return answer;
    }
}