Skip to content

Commit 89d227f

Browse files
authored
Implement binary search to find minimum in rotated array (#1077)
2 parents 357693f + 082ca9f commit 89d227f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int findMin(int[] nums) {
3+
int left = 0;
4+
int right = nums.length - 1;
5+
while (left < right) {
6+
int mid = left + (right - left) / 2;
7+
if (nums[mid] > nums[right]) {
8+
left = mid + 1;
9+
} else {
10+
right = mid;
11+
}
12+
}
13+
return nums[left];
14+
}
15+
}

0 commit comments

Comments
 (0)