【leetcode】分糖果

int distributeCandies(int* candyType, int candyTypeSize){    
    int cnt=0;
    int hash[200001]={0};
    for (int i=0; i<candyTypeSize; i++){
        if (hash[candyType[i]+100000]==0){
            hash[candyType[i]+100000]++;
            cnt++;
        }
    }
    return (cnt<candyTypeSize/2)?cnt :candyTypeSize/2;
}
原文地址:https://www.cnblogs.com/ganxiang/p/14009489.html