๋ชฉ์ฐจ
LeetCode - Problems - Algorithms - 1512. Number of Good Pairs
Problem Description
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.
Example:

Constraints:

My Solution (Python)
class Solution(object):
def numIdenticalPairs(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
answer = 0
length = len(nums)
for i in range(length):
for j in range(i, length):
if nums[i] == nums[j] and i < j:
answer += 1
return answer
'Problem solving > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [LeetCode] 1603. Design Parking System (Python) (0) | 2021.01.10 |
|---|---|
| [LeetCode] 1528. Shuffle String (Python) (0) | 2021.01.10 |
| [LeetCode] 1470. Shuffle the Array (Python) (0) | 2021.01.10 |
| [LeetCode] 1365. How Many Numbers Are Smaller Than the Current Number (Python) (0) | 2021.01.10 |
| [LeetCode] 1108. Defanging an IP Address (Python) (0) | 2021.01.10 |