All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0501_0600.s0575_distribute_candies.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g0501_0600.s0575_distribute_candies;

// #Easy #Array #Hash_Table

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy