[leetcode]575. Distribute Candies

problem

code

1st try

class Solution {
    public int distributeCandies(int[] candyType) {
        int len = candyType.length;
        int canEat = len / 2;
        
        Set<Integer> set = 
          Arrays.stream(candyType).boxed().collect(Collectors.toSet());

      	int answer = canEat > set.size() ? set.size() : canEat;
        return answer;
    }
}

좋은 웹페이지 즐겨찾기