import java.util.*;
class Solution {
    public int solution(int[] array) {
        int count = 0;
        int answer = 0;
        int maxBindo = 0;
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int num : array){
            int bindo = map.getOrDefault(num, 0) + 1;
            if(bindo > maxBindo){
                maxBindo = bindo;
                answer = num;
            }
            else if(bindo == maxBindo){
                answer = -1;
            }
            map.put(num, bindo);
        }
        return answer;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

피자 나눠 먹기 (1)  (0) 2024.01.26
짝수는 싫어요  (0) 2024.01.25
배열 두 배 만들기  (0) 2024.01.24
분수의 덧셈  (0) 2024.01.24
flag에 따라 다른 값 반환하기  (0) 2024.01.23

+ Recent posts