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

 

posted @ 2020-11-20 10:11  温暖了寂寞  阅读(84)  评论(0编辑  收藏  举报