파비의 매일매일 공부기록

2023.09.19 Today's Challenge 본문

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
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.09.21 Today's Challenge  (0) 2023.09.21
2023.09.20 Today's Challenge  (0) 2023.09.20
2023.09.18 Today's Challenge  (0) 2023.09.18
2023.09.17 Today's Challenge  (0) 2023.09.17
2023.09.16 Today's Challenge  (0) 2023.09.16
Comments