-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path154.java
More file actions
39 lines (39 loc) · 1.23 KB
/
154.java
File metadata and controls
39 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int findMin(int[] nums) {
int start = 0, end = nums.length - 1;
while (start < end) {
int mid = (start + end) / 2;
if (nums[mid] > nums[end]) {
start = mid + 1;
} else if (nums[mid] < nums[end]) {
end = mid;
} else {
end--;
}
}
return nums[start];
}
}
__________________________________________________________________________________________________
sample 34640 kb submission
class Solution {
public int findMin(int[] nums) {
int l = 0, h = nums.length - 1;
while(l < h){
int mid = l + (h - l)/2;
System.out.println(l+" "+mid+" "+h);
if(nums[h] > nums[mid]){// rotation in low to mid
h = mid;
}
else if(nums[mid] > nums[h]){
l = mid+1;
}else{
h--;
}
}
return Math.min(nums[l],nums[h]);
}
}
__________________________________________________________________________________________________