leetcode_392判断子序列

2020-07-27  本文已影响0人  看到这朵小fa了么

遍历t,同时更新s的索引,当最后都能匹配上则s为t的子序列

var isSubsequence = function(s, t) {
  let c = 0
  for(let i=0; i<t.length; i++){
      if(s[c]===t[i]){
          c++
      }
  }
  if(c===s.length) {
      return true
  } else return false
};
上一篇 下一篇

猜你喜欢

热点阅读