Is Subsequence
- javascript
- typescript
- string
- two pointers
Problem URL:Is Subsequence
My Solution
JavaScript / TypeScript
const isSubsequence = (s: string, t: string): boolean => {
let i = 0,
j = 0;
while (i < s.length && j < t.length) {
if (s[i] === t[j]) {
i += 1;
j += 1;
} else {
j += 1;
}
}
return i === s.length;
};
Let's Connect
Twitter •GitHub •LinkedIn