【leetcode】好数对的数目

 

int numIdenticalPairs(int* nums, int numsSize){
    int hash[101] = {0};
    int ret = 0;

    for(int i = 0; i < numsSize; i++)
    {
        hash[nums[i]]++;
        ret += hash[nums[i]] - 1;
    }

    return ret;
}

 

posted @ 2020-09-14 11:32  温暖了寂寞  阅读(139)  评论(0编辑  收藏  举报