leetcode 575. 分糖果(Java版)
生活随笔
收集整理的這篇文章主要介紹了
leetcode 575. 分糖果(Java版)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
https://leetcode-cn.com/problems/distribute-candies/
題解
class Solution {public int distributeCandies(int[] candyType) {Set<Integer> set = new HashSet<>();for (int i : candyType) {set.add(i);}return Math.min(set.size(), candyType.length / 2);} }總結
以上是生活随笔為你收集整理的leetcode 575. 分糖果(Java版)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode 572. 另一个树的子
- 下一篇: leetcode 589. N 叉树的前