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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/caaf764e-1ff8-4520-aab6-1b8134f61e5c/Screen_Shot_2021-03-30_at_2.42.58_PM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3e9b8713-31d4-4255-86d4-1595d097e268/Untitled.png

"""
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)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3f98c839-e6b2-4306-ba32-1c5d51117d3f/Screen_Shot_2021-03-30_at_2.56.16_PM.png