본문 바로가기

IT/코딩테스트

[Leetcode] 287. Find the Duplicate Number

728x90

https://leetcode.com/problems/find-the-duplicate-number/

class Solution:
    def findDuplicate(self, nums: List[int]) -> int:

        nums_set = set()

        for n in nums:
            if n in nums_set:
                return n
            else:
                nums_set.add(n)
    
        return -1
728x90