Q&A
제 솔루션도 확인해주실수 있나요?
저도 이 고민이 들어서 스택으로 바꿔서 풀어봤는데, 같은 고민을 하신 분이 계셨네요. 저는 이렇게 풀어봤습니다. function solution(need, plan) { let answer = "YES"; plan = plan.split("").reverse(); for (let x of need) { while (x !== plan[plan.length - 1]) { plan.pop(); } if (!plan.length) { answer = "NO"; break; } } return answer; } console.log(solution("CBA", "CBDAGE")); // YES console.log(solution("CBA", "CABA")); // YES console.log(solution("CBA", "CBBDAGE")); // YES console.log(solution("CBA", "CBDDAB ")); // YES console.log(solution("CBA", "CBDAGAE")); // YES console.log(solution("ABC", "BABC")); // YES
- Likes
- 0
- Comments
- 2
- Viewcount
- 316

