Number of Good Pairs - LeetCode
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.
"""
1512. Number of Good Pairs
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.
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
"""
nums = [1,1,1,1]
i = 0
count = 0
while i < len(nums):
j = i + 1
while j < len(nums):
if nums[i] == nums[j]:
count += 1
j += 1
i += 1
print(count)