Skip to content

Commit 3da533f

Browse files
committed
find-minimum-in-rotated-sorted-array solution
1 parent 54fcea1 commit 3da533f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def findMin(self, nums: List[int]) -> int:
3+
"""
4+
μ‹œκ°„λ³΅μž‘λ„: O(log n) - 이진 탐색
5+
κ³΅κ°„λ³΅μž‘λ„: O(1) - μΆ”κ°€ λ©”λͺ¨λ¦¬ μ—†μŒ
6+
"""
7+
8+
# 이진탐색
9+
left = 0
10+
right = len(nums) - 1
11+
12+
while left < right:
13+
# 쀑간 인덱슀
14+
mid = (left+right)//2
15+
16+
# μ΅œμ†Œκ°’μ΄ 였λ₯Έμͺ½μ— 있음
17+
if nums[mid] > nums[right]:
18+
left = mid + 1
19+
# μ΅œμ†Œκ°’μ΄ μ™Όμͺ½(쀑간포함)에 있음
20+
else:
21+
right = mid
22+
23+
# μ΅œμ’… μ΅œμ†Œκ°’
24+
return nums[left]

0 commit comments

Comments
Β (0)