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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 41. First Missing Positive (1) | 2024.03.26 |
---|---|
[Leetcode] 442. Find All Duplicates in an Array (0) | 2024.03.25 |
[Leetcode] 143. Reorder List (0) | 2024.03.23 |
[Leetcode] 234. Palindrome Linked List (0) | 2024.03.22 |
[Leetcode] 206. Reverse Linked List (0) | 2024.03.21 |