Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Last active June 27, 2020 16:20
Show Gist options
  • Save dalcon10028/de018646ab67f3f7377401da863e6769 to your computer and use it in GitHub Desktop.
Save dalcon10028/de018646ab67f3f7377401da863e6769 to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0; i<n; i++) a[i] = sc.nextInt();
Arrays.sort(a);
int m = sc.nextInt();
for(int i=0; i<m; i++){
int result=0, low=0, high=n-1;
int target = sc.nextInt();
while(low<=high){
int mid = (low+high)/2;
if(a[mid]==target) {
result=1;
break;
}
if(a[mid]>target) high = mid-1;
else low = mid+1;
}
System.out.println(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment