Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e48166

Browse files
committedFeb 5, 2025·
[week9](gmlwls96) Find Minimum in Rotated Sorted Array
1 parent aa93499 commit 6e48166

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+
// 시간 : O(logN) 공간 : O(1)
3+
// 이분탐색.
4+
fun findMin(nums: IntArray): Int {
5+
var left = 0
6+
var right = nums.lastIndex
7+
8+
while (left <= right){
9+
val mid = (left + right)/2
10+
when{
11+
nums[mid-1] > nums[mid] -> {
12+
return nums[mid]
13+
}
14+
nums[0] < nums[mid] -> {
15+
left = mid + 1
16+
}
17+
else -> {
18+
right = mid -1
19+
}
20+
}
21+
}
22+
return nums[0]
23+
}
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.