Skip to content

Commit 818f307

Browse files
committed
카드뭉치(중급)
1 parent 24561a7 commit 818f307

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

unn04012/queue/card.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(cards1, cards2, goal) {
2+
const reversedCard1 = cards1.reverse();
3+
const reversedCard2 = cards2.reverse();
4+
5+
for (const word of goal) {
6+
let flag = false;
7+
if (reversedCard1[reversedCard1.length - 1] === word) {
8+
reversedCard1.pop();
9+
flag = true;
10+
} else if (reversedCard2[reversedCard2.length - 1] === word) {
11+
reversedCard2.pop();
12+
flag = true;
13+
}
14+
if (!flag) return 'No';
15+
}
16+
17+
return 'Yes';
18+
}
19+
20+
console.log(solution(['i', 'drink', 'water'], ['want', 'to'], ['i', 'want', 'to', 'drink', 'water']));

0 commit comments

Comments
 (0)