[Programmers] 폰켓몬 - 찾아라 프로그래밍 마에스터

동민·2021년 3월 11일
import java.util.HashSet;

// 폰켓몬 - 찾아라 프로그래밍 마에스터
public class Ponkemon {

	public int solution(int[] nums) {

		HashSet<Integer> set = new HashSet<>();
		for (int ele : nums) {
			set.add(ele);
			if (set.size() == nums.length / 2) {
				break;
			}
		}
		return set.size();
	}

	public static void main(String[] args) {

		Ponkemon s = new Ponkemon();

		int nums1[] = { 3, 1, 2, 3 };
		int nums2[] = { 3, 3, 3, 2, 2, 4 };
		int nums3[] = { 3, 3, 3, 2, 2, 2 };

		System.out.println(s.solution(nums1)); // 2
		System.out.println(s.solution(nums2)); // 3
		System.out.println(s.solution(nums3)); // 2

	}

}
profile
BE Developer

0개의 댓글