Created
February 17, 2020 14:32
-
-
Save toantd90/a30e2faf0684616dcff2d99432e8af68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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