Skip to content

Instantly share code, notes, and snippets.

@toantd90
Created February 17, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toantd90/a30e2faf0684616dcff2d99432e8af68 to your computer and use it in GitHub Desktop.
Save toantd90/a30e2faf0684616dcff2d99432e8af68 to your computer and use it in GitHub Desktop.
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isSubsequence = function(s, t) {
const len = s.length;
if (len === 0) return true;
let sIndex = 0;
let pos = 0;
while (sIndex < len) {
pos = t.indexOf(s[sIndex], pos);
if (pos === -1)
return false;
if (s[sIndex] === s[sIndex-1]) {
pos += 1;
}
sIndex++;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment