주식가격


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

문제보기
Alt text

소스코드

class Solution {
   public int[] solution(int[] prices) {
        int priceLength = prices.length;
        int[] answer = new int[priceLength];

        for (int i = 0; i < priceLength; i++) {
            int keep = 0;

            for (int j = i + 1; j < priceLength; j++) {
                keep++;

                if (prices[i] > prices[j]) break;
            }

            answer[i] = keep;
        }

        return answer;
    }
}