[leetcode] 392. Is Subsequence (Medium)
原题
判断子序列
/**
* @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;
};