sIdx
선언t
를 순회하며 같은 문자일 경우 sIdx
증가sIdx
가 s
의 길이가 되었다는 것은 모든 문자가 확인되었다는 의미이므로 true
반환s
를 충분히 탐색하지 못했단 의미이므로 false
반환function isSubsequence(s: string, t: string): boolean {
if(!s.length && !t.length) return true
let sIdx = 0;
for (const char of t) {
if (char === s[sIdx]) sIdx++;
if (sIdx === s.length) return true
}
return false
};