Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Sep 22, 2023
1 parent 5e752b7 commit 856149d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions coding_interviews/leetcode/easy/is-subsequence/is-subsequence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://leetcode.com/problems/is-subsequence

function isSubsequence(s, t) {
let sIndex = 0;
let tIndex = 0;

while (sIndex < s.length && tIndex < t.length) {
let sChar = s[sIndex];
let tChar = t[tIndex];

if (sChar === tChar) {
sIndex++;
tIndex++;
} else {
tIndex++;
}
}

return sIndex === s.length;
}

0 comments on commit 856149d

Please sign in to comment.