Jam's story

[로또의 최고 순위와 최저 순위] 본문

코딩테스트/프로그래머스

[로또의 최고 순위와 최저 순위]

애플쩀 2022. 5. 26. 08:13
import java.util.*;

class Solution {
     public static int[] solution(int[] lottos,int[] win_nums){
   
        int[] rank={6,6,5,4,3,2,1};
        int cnt=0;
        int zero=0;
        Arrays.sort(win_nums);
       for (int i = 0; i <lottos.length; i++) {
           if(Arrays.binarySearch(win_nums, lottos[i])>-1)
            cnt++;
            else if(lottos[i]==0) zero++;
       }
       int[] answer={rank[cnt+zero],rank[cnt]};
       return answer;
    }
}

 

binarySearch()
binarySearch() 메소드의 반환값이 매개변수로 넣은값
존재하면 해당 값의 인덱스번호를 반환하고 그렇지 않으면 음수를 반환한다

 

'코딩테스트 > 프로그래머스' 카테고리의 다른 글

[숫자 문자열과 영단어]  (0) 2022.06.13
[키패드 누르기]  (0) 2022.05.30
[숫자 문자열과 영단어]  (0) 2022.05.30
[신규 아이디 추천]  (0) 2022.05.27
[신고 결과 받기]  (0) 2022.05.26
Comments