240909
λ¬Έμ : μΉ΄λ λμΉ λμ΄λ : Lv.1
νμ΄
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