-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.java
More file actions
35 lines (34 loc) · 923 Bytes
/
Copy pathtest3.java
File metadata and controls
35 lines (34 loc) · 923 Bytes
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
import java.util.*;
/*
*/
public class test3 {
public static int lowerBound(int[] nums,int target){
int left = 0;
int right = nums.length-1;
while (left<=right) {
int mid = left + (right-left)/2;
if(nums[mid]<target){
left = mid+1;
}else{
right = mid-1;
}
}
return left;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0; i<n; i++){
nums[i] = sc.nextInt();
}
int target = sc.nextInt();
int left = lowerBound(nums, target);
if(left==n||nums[left]!=target){
System.out.print("-1 -1");
return;
}
int right = lowerBound(nums, target+1)-1;
System.out.print(left+" "+right);
}
}