[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;
};
posted @ 2018-10-11 14:37  Ruohua3kou  阅读(100)  评论(0编辑  收藏  举报