[LeetCode] 392. Is Subsequence (
2018-11-02 本文已影响0人
弱花
原题
判断子序列
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isSubsequence = function(s, t) {
var sl = s.length;
var tl = t.length;
if (sl === 0) {
return true;
}
if (tl < sl) {
return false;
}
var sindex = 0;
for (let i = 0; i < tl; i++) {
if (s[sindex] == t[i]) {
sindex++;
}
if (sindex === sl) {
return true;
}
}
return false;
};