[Leetcode/python] Number of Good Pairs

김미영·2024년 4월 10일
0

LeetCode

목록 보기
9/11

📌 문제

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


📝 해결

시간 복잡도 : O(n^2)

class Solution:
    def numIdenticalPairs(self, nums: List[int]) -> int:
        count = 0
        for i in range(len(nums)):
            for j in range(len(nums)):
                if nums[i] == nums[j] and i < j:
                    count += 1
        return count

0개의 댓글