Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created August 22, 2020 23:23
Show Gist options
  • Save niklasjang/44ae46d8dad6e84010e42513c198bc64 to your computer and use it in GitHub Desktop.
Save niklasjang/44ae46d8dad6e84010e42513c198bc64 to your computer and use it in GitHub Desktop.
[PS][java][BinarySearch]/[수 찾기]/O(n)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
static int n,m;
static int[] arr, find;
static int ans=0;
static boolean exist(int next){
for(int i=0; i<n; i++){
if(arr[i] == next){
return true;
}
}
return false;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
String[] str = br.readLine().split(" ");
arr = new int[n];
for(int i=0; i<n; i++){
arr[i] = Integer.parseInt(str[i]);
}
m = Integer.parseInt(br.readLine());
String[] str2 = br.readLine().split(" ");
find = new int[m];
for(int i=0; i<m; i++){
find[i] = Integer.parseInt(str2[i]);
}
for(int i=0; i<m; i++){
int next = find[i];
if(exist(next)){
System.out.println(1);
}else{
System.out.println(0);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment