Back to course home
0% completed
Vote For New Content
Using 2 pointers approach
amazonintern101
Aug 14, 2023
class Solution: def numGoodPairs(self, nums): pairCount = 0 # TODO: Write your code here left, right = 0,0 while left < len(nums) - 1: right += 1 if nums[left] == nums[right] and left < right: pairCount += 1 if right == len(nums) - 1: left += 1 right = left return pairCount
0
0
Comments
Comments
Adebowale Oduyemi2 years ago
This looks good but is O(n^2) solution.
On this page