지구정복

[구현] 프로그래머스 - 폰켓몬(1845) 자바 본문

데이터 엔지니어링 정복/Algorithm

[구현] 프로그래머스 - 폰켓몬(1845) 자바

eeaarrtthh 2022. 8. 5. 23:52
728x90
반응형
SMALL

-문제

https://school.programmers.co.kr/learn/courses/30/lessons/1845

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

-풀이

package implementation;

import java.util.HashSet;

public class pro1845 {
    public static void main(String[] args) {
        int[] nums = {3,1,2,3};
        //int[] nums = {3,3,3,2,2,4};
        //int[] nums = {3,3,3,2,2,2};

        int max = nums.length / 2;

        //중복제거
        HashSet<Integer> set = new HashSet<>();
        
        for( int num : nums ) {
            set.add(num);
        }

        //중복을 제거한 셋의 크기가 max보다 크면 max,
        //작으면 set의 size리턴
        if( set.size() > max ) {
            System.out.println( max );
        } else {
            System.out.println( set.size() );
        }
    }
}
728x90
반응형
LIST
Comments