애플리케이션 개발/알고리즘

[프로그래머스] 폰켓몬

sofiaaa 2022. 7. 6. 08:52
반응형
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

class Solution {
    public int solution(int[] nums) {
         int answer = 0;

        List<Integer> numbers = new ArrayList<>();
        for(int i =0 ;i < nums.length; i++){
            numbers.add(nums[i]);
        }

        List<Integer> finalNumbers = numbers.stream().distinct().collect(Collectors.toList());

        Integer size = finalNumbers.size();
        Integer comparedSize = nums.length / 2;
        answer = (comparedSize < size) ? comparedSize : size;

        return answer;
    }
}
반응형

'애플리케이션 개발 > 알고리즘' 카테고리의 다른 글

없는 숫자 더하기  (0) 2022.10.20
최대값과 최소값  (0) 2022.09.23
[프로그래머스] 행렬의 곱셉  (0) 2022.07.03
[프로그래머스] 2016년  (0) 2022.07.01
[프로그래머스] 모의고사  (0) 2022.06.30