Skip to content

Commit 419bb0f

Browse files
committed
Card bundle / 중급
1 parent 8e545d2 commit 419bb0f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/159994
2+
3+
// 1. 큐를 활용한 방법
4+
const solution1 = (cards1, cards2, goal) => {
5+
for (let i = 0; i < goal.length; i++) {
6+
if (goal[i] === cards1[0]) {
7+
cards1.shift();
8+
} else if (goal[i] === cards2[0]) {
9+
cards2.shift();
10+
} else return "No";
11+
}
12+
return "Yes";
13+
};
14+
15+
// 2. 포인터를 활용한 방법
16+
const solution2 = (cards1, cards2, goal) => {
17+
let p1 = 0,
18+
p2 = 0;
19+
20+
for (const word of goal) {
21+
if (word === cards1[p1]) {
22+
p1++;
23+
} else if (word === cards2[p2]) {
24+
p2++;
25+
} else return "No";
26+
}
27+
return "Yes";
28+
};

0 commit comments

Comments
 (0)