LeetCode 1512. 好数对的数目

https://leetcode-cn.com/problems/number-of-good-pairs/

 

Java

public int numIdenticalPairs(int[] nums) {
        if (nums.length < 0) {
            return 0;
        }
        int[] counts = new int[101];
        int count = 0;
        for (int num : nums) {
            count += counts[num];
            counts[num]++;
        }
        return count;
    }

  

 

posted @ 2020-10-02 17:13  Risfeng  阅读(138)  评论(0编辑  收藏  举报