const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(filePath).toString().trim().split('\n');
let [N, numArr, M, arr] = input;
numArr = numArr.trim().split(' ');
arr = arr.split(' ');
M = Number(M);
N = Number(N);
let answer = [];
for(let i=0; i < M; i++) {
let check = false;
for(let j=0; j < N; j++) {
if(arr[i] === numArr[j]) {
answer.push(1);
check = true;
}
}
!check ? answer.push(0) : null;
}
console.log(answer.join(' '));
시간초과가 발생해서 Set객체를 활용했다.
const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(filePath).toString().trim().split('\n');
let [N, numArr, M, arr] = input;
numArr = numArr.trim().split(' ');
arr = arr.split(' ');
N = Number(N);
M = Number(M);
const answer = [];
const set = new Set();
for(let i=0; i < N; i++) {
set.add(numArr[i]);
}
for(let i=0; i < M; i++) {
if(set.has(arr[i])) {
answer.push(1);
} else {
answer.push(0);
}
}
console.log(answer.join(' '));