Find Minimum in Rotated Sorted Array II LeetCode solution in Java

1
class Solution {
2
public int findMin(int[] nums) {
3
int l = 0;
4
int h = nums.length - 1;
5
while (l < h) {
6
while (l < h && nums[l] == nums[l + 1]) ++l;
7
while (l < h && nums[h] == nums[h - 1]) --h;
8
int mid = l + (h - l) / 2;
9
if (nums[mid] > nums[h]) { // smaller elements are in the right side
10
l = mid + 1;
11
} else {
12
h = mid;
13
}
14
}
15
return nums[l];
16
}
17
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0