Skip to content

Commit 3b62c80

Browse files
committed
find minimun in rotated sorted array
1 parent 3932e72 commit 3b62c80

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Runtime: 0ms
3+
* Time Complexity: O(log n)
4+
*
5+
* Memory: 43.81MB
6+
* Space Complexity: O(1)
7+
*
8+
* Approach: 이진 탐색
9+
*/
10+
class Solution {
11+
public int findMin(int[] nums) {
12+
int left = 0;
13+
int right = nums.length-1;
14+
15+
while (left < right) {
16+
int mid = left + (right-left)/2;
17+
if (nums[mid] <= nums[right]) {
18+
right = mid;
19+
} else {
20+
left = mid + 1;
21+
}
22+
}
23+
24+
return nums[left];
25+
}
26+
}

0 commit comments

Comments
 (0)