Problem Solving/LeetCode
2023.09.19 Today's Challenge
fabichoi
2023. 9. 19. 23:45
https://leetcode.com/problems/find-the-duplicate-number/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제의 조건으로는 리스트를 변형하지 말라고 했으나, 그냥 간단하게 구현함.
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
nums.sort()
before = -1
for num in nums:
if before == num:
return num
before = num
return -1
반응형