Created
June 9, 2020 07:20
-
-
Save RP-3/6aa0c33787ac38c1b189866986109759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
if(!s.length) return true; | |
let i = 0; | |
for(let j=0; j<t.length; j++){ | |
if(t[j] !== s[i]) continue; | |
if(++i === s.length) return true; | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment