상위 150개 인터뷰쉬움

회전 정렬 배열에서 최소값 찾기

'회전 정렬 배열에서 최소값 찾기' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

오름차순으로 정렬된 n 길이의 배열이 1회에서 n회 사이에서 회전된다고 가정합니다. 예를 들어, [0,1,2,4,5,6,7] 배열은 4번 회전되면 [4,5,6,7,0,1,2]이 될 수 있습니다.

배열 [a[0], a[1], ..., a[n-1]]을 한 번 회전하면 [a[n-1], a[0], a[1], ..., a[n-2]]이 됩니다.

고유 요소의 정렬된 회전 배열 nums이 주어지면 이 배열의 최소 요소를 반환합니다.

O(log n) 시간에 실행되는 알고리즘을 작성해야 합니다.

findMin(nums: List[int]) -> int 함수를 작성하세요.

제약
  • n == len(nums)
  • 1 <= n <= 5000
  • -5000 <= nums[i] <= 5000
  • All integers in nums are unique
  • nums is sorted and rotated between 1 and n times

Example 1
Input
nums = [3, 4, 5, 1, 2]
Output
1
Explanation

The original array was [1,2,3,4,5] rotated 3 times. The minimum is 1.

Example 2
Input
nums = [4, 5, 6, 7, 0, 1, 2]
Output
0
Explanation

The original array was [0,1,2,4,5,6,7] rotated 4 times. The minimum is 0.

Example 3
Input
nums = [11, 13, 15, 17]
Output
11
Explanation

Array is not rotated (or rotated n times). The minimum is the first element.

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 리소스

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