Skip to content

Commit 7e1db34

Browse files
committed
improve problem explanation and approach for Find Minimum in Rotated Array
1 parent 108dd8b commit 7e1db34

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

โ€Žfind-minimum-in-rotated-sorted-array/KwonNayeon.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""
2-
Constraints:
3-
- n == nums.length
4-
- 1 <= n <= 5000
5-
- -5000 <= nums[i] <= 5000
6-
- All the integers of nums are unique.
7-
- nums is sorted and rotated between 1 and n times.
2+
Input/Output/Constraints:
3+
- Input: A rotated sorted array (e.g., [4,5,6,7,0,1,2])
4+
- Output: The minimum element in the array (e.g., 0)
5+
- Constraints: Algorithm must run in O(log n) time
86
97
Time Complexity: O(log n)
108
- ์ด์ง„ ํƒ์ƒ‰์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ๋งค ๋‹จ๊ณ„๋งˆ๋‹ค ํƒ์ƒ‰ ๋ฒ”์œ„๊ฐ€ ์ ˆ๋ฐ˜์œผ๋กœ ์ค„์–ด๋“ฆ
@@ -16,19 +14,17 @@
1614
1. ์ด์ง„ ํƒ์ƒ‰(Binary Search) ํ™œ์šฉ
1715
2. mid์™€ right ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ์กฐ๊ฑด์„ ๋‚˜๋ˆ”
1816
- Case 1: nums[mid] > nums[right]
19-
- ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„์ด ์ •๋ ฌ๋˜์–ด ์žˆ์ง€ ์•Š์Œ
2017
- ์ตœ์†Ÿ๊ฐ’์€ mid ์˜ค๋ฅธ์ชฝ์— ์กด์žฌ
2118
- left = mid + 1
2219
- Case 2: nums[mid] <= nums[right]
23-
- mid๋ถ€ํ„ฐ right๊นŒ์ง€๋Š” ์ •๋ ฌ๋˜์–ด ์žˆ์Œ
2420
- ์ตœ์†Ÿ๊ฐ’์€ mid๋ฅผ ํฌํ•จํ•œ ์™ผ์ชฝ์— ์กด์žฌ ๊ฐ€๋Šฅ
2521
- right = mid
22+
3. Pivot์ด ์ผ์–ด๋‚œ ์ง€์ ์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜
2623
"""
2724

2825
class Solution:
2926
def findMin(self, nums: List[int]) -> int:
30-
left = 0
31-
right = len(nums) - 1
27+
left, right = 0, len(nums) - 1
3228

3329
while left < right:
3430
mid = (left + right) // 2

0 commit comments

Comments
ย (0)