美文网首页
[LeetCode] 392. Is Subsequence (

[LeetCode] 392. Is Subsequence (

作者: 弱花 | 来源:发表于2018-11-02 11:36 被阅读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;
};

相关文章

网友评论

      本文标题:[LeetCode] 392. Is Subsequence (

      本文链接:https://www.haomeiwen.com/subject/bjiqxqtx.html