Skip to Main Content

Detect the Only Duplicate in a List

Problem URL:Detect the Only Duplicate in a List

My Solution

Python

def solve(nums):
    nums_sorted = sorted(nums)

    for i in range(len(nums)):
        if i > len(nums) - 2:
            break

        a = nums_sorted[i]
        b = nums_sorted[i+1]

        if a == b:
            return a

Let's Connect

Twitter GitHub LinkedIn