g0501_0600.s0575_distribute_candies.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
package g0501_0600.s0575_distribute_candies;
// #Easy #Array #Hash_Table #2022_08_10_Time_67_ms_(42.81%)_Space_111.2_MB_(25.92%)
import java.util.HashSet;
import java.util.Set;
public class Solution {
public int distributeCandies(int[] candyType) {
Set set = new HashSet<>();
for (int i : candyType) {
set.add(i);
}
return Math.min(set.size(), candyType.length / 2);
}
}