본문 바로가기
알고리즘 & 자료구조/프로그래머스

주식가격

by 신재권 2023. 2. 2.
package programmers;

import java.util.Arrays;

public class 주식가격 {

   public static 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;
   }

   public static void main(String[] args) {
      System.out.println(Arrays.toString(solution(new int[] {1, 2, 3, 2, 3})));
      System.out.println(Arrays.toString(solution(new int[] {1, 2, 3, 2, 3, 1})));
      System.out.println(Arrays.toString(solution(new int[] {3, 1})));

   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

땅따먹기  (0) 2023.02.04
스킬트리  (0) 2023.02.03
주차 요금 계산  (0) 2023.02.01
n 진수 게임  (1) 2023.01.31
피로도  (0) 2023.01.29