[프로그래머스] 주식 가격(자바)

Rena·2022년 4월 6일
0

알고리즘 문제풀이

목록 보기
25/45

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

        for(int i = 0; i< prices.length; i++) {
            int second = 0;
            for(int j = i+1 ; j< prices.length; j++) {
                second++;
                if(prices[i] > prices[j]) break;
            }
            answer[i] = second;
        }
        return answer;
    }

    public static void main(String[] args) {
        int[] prices = {1,2,3,2,3};
        Solution st = new Solution();
        int[] answer = st.solution(prices);
        for(int i=0; i< answer.length; i++) {
            System.out.println(answer[i]);
        }
    }

}
profile
일을 사랑하고 싶은 개발자

0개의 댓글