Skip to content

Commit d679fbc

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 154_Find_Minimum_in_Rotated_Sorted_Array_II.java
1 parent 6683631 commit d679fbc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int findMin(int[] nums) {
3+
if (nums == null || nums.length == 0) {
4+
return 0;
5+
}
6+
7+
int start = 0, end = nums.length - 1;
8+
9+
while (start < end) {
10+
int mid = start + (end - start) / 2;
11+
12+
if (nums[mid] == nums[end]) {
13+
--end;
14+
} else if (nums[mid] > nums[end]) {
15+
start = mid + 1;
16+
} else {
17+
end = mid;
18+
}
19+
}
20+
21+
return nums[start];
22+
}
23+
}

0 commit comments

Comments
 (0)