240909
ํ์ด
function solution(cards1, cards2, goal) {
let index1 = 0; // cards1์ ํ์ฌ ์ธ๋ฑ์ค
let index2 = 0; // cards2์ ํ์ฌ ์ธ๋ฑ์ค
// goal์ ๋จ์ด๋ฅผ ์์๋๋ก ํ์ธ
for (let word of goal) {
// cards1์์ ๋จ์ด๋ฅผ ์ฌ์ฉํด์ผ ํ ๊ฒฝ์ฐ
if (index1 < cards1.length && cards1[index1] === word) {
index1++; // cards1์ ๋ค์ ๋จ์ด๋ก ์ด๋
}
// cards2์์ ๋จ์ด๋ฅผ ์ฌ์ฉํด์ผ ํ ๊ฒฝ์ฐ
else if (index2 < cards2.length && cards2[index2] === word) {
index2++; // cards2์ ๋ค์ ๋จ์ด๋ก ์ด๋
}
// ๋ ๋ค ์๋ ๊ฒฝ์ฐ ๋ชฉํ ๋จ์ด ๋ฐฐ์ด์ ๋ง๋ค ์ ์์
else {
return "No";
}
}
// ๋ชจ๋ ๋จ์ด๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ฌ์ฉ๋์์ ๊ฒฝ์ฐ
return "Yes";
}Last updated