close

Given an array of integers nums.

A pair (i,j) is called good if nums[i] == nums[j] and i < j.

Return the number of good pairs.

暴力破解:
class Solution:
    def numIdenticalPairs(self, nums: List[int]) -> int:
        count=0
        for x in range(len(nums)):
            for y in range(x+1,len(nums)):
                if nums[x]==nums[y]:
                    count+=1
        return count

arrow
arrow
    文章標籤
    Leetcode python3
    全站熱搜

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()