-
-
Save niklasjang/44ae46d8dad6e84010e42513c198bc64 to your computer and use it in GitHub Desktop.
[PS][java][BinarySearch]/[수 찾기]/O(n)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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