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

숫자게임

by 신재권 2022. 11. 19.
package programmers;

import java.util.Arrays;

public class 숫자게임 {
   public static int solution(int[] A, int[] B) {

      int answer = 0;
      Arrays.sort(A);
      Arrays.sort(B);
      int idx = B.length-1;
      for (int i = A.length - 1; i >= 0; i--) {
         if (A[i] < B[idx]) {
            idx--;
            answer++;
         }
      }

      return answer;
   }

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

}

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

게임 맵 최단거리  (0) 2022.12.02
위장  (0) 2022.12.02
예산  (0) 2022.11.19
가장 큰 수  (0) 2022.11.17
기지국 설치  (0) 2022.11.16