-
프로그래머스 - 숫자 게임 [자바]Algorithms/- 프로그래머스 2022. 2. 21. 23:06
- 문제 링크 : 숫자 게임
정답(Solution)
import java.util.*; class Solution { public int solution(int[] A, int[] B) { Arrays.sort(A); Arrays.sort(B); int answer = 0; int idx = B.length-1; for(int i=A.length-1; i>=0; i--){ if(A[i] < B[idx]){ idx--; answer++; } } return answer; } }
분석
- 효율성 테스트 통과가 어려운 문제
- 이중 for문을 사용하면 쉽게 풀 수 있지만 효율성 테스트를 통과할 수 없다.
- 그래서 2배열을 모두 정렬 후 단일 for문에서 A, B의 크기를 비교하여야 풀이를 할 수 있다.
반응형