상위 150개 인터뷰쉬움

중복 번호 찾기

'중복 번호 찾기' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

n + 1개의 정수를 포함하는 정수 배열 nums가 주어지며, 각 정수는 [1, n] 범위에 속합니다.

nums에는 반복되는 숫자가 하나만 있습니다. 이 반복된 숫자를 반환합니다.

배열 번호를 수정하지 않고 일정한 추가 공간만 사용하여 문제를 해결해야 합니다.

중복된 숫자를 반환하는 findDuplicate(nums: list) -> int 함수를 구현하세요.

제약
  • 1 <= n <= 100000
  • nums.length == n + 1
  • 1 <= nums[i] <= n
  • There is only one repeated number in nums, but it could be repeated more than once

Example 1
Input
[1,3,4,2,2]
Output
2
Explanation

The duplicate number is 2. It appears twice in the array.

Example 2
Input
[3,1,3,4,2]
Output
3
Explanation

The duplicate number is 3. It appears twice in the array.

Example 3
Input
[3,3,3,3,3]
Output
3
Explanation

The duplicate number is 3. It appears five times.

Need a Hint?
세트나 힙과 같은 연결 목록 관련 데이터 구조를 사용하는 것을 고려해보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.