Algorithm/Programmers
[Lv.3] 숫자 게임
시롱시롱
2023. 4. 21. 18:44
import java.util.Arrays;
import java.util.stream.Collectors;
class Solution {
public int solution(int[] A, int[] B) {
int answer = 0;
Arrays.sort(A);
Arrays.sort(B);
int searchIndex=-1;
boolean endFlag=false;
for (int i : A) {
while (true){
searchIndex++;
if(searchIndex>=B.length){
endFlag=true;
break;
}
if(B[searchIndex]>i){
//현재 A가 가진 가장 낮은 패에 대해서 가장 낮은패로 승리하기
answer++;
break;
}
}
if(endFlag)
break;
}
return answer;
}
}
ez