无重复字符的最长子串

无重复字符的最长子串

(1)

lengthOfLongestSubstring(s){
      let arr = s.split('');
      let nums = [];
      let len = arr.length;
      let resMax = 0;
      let index = 0;
      while(index < len){
        let max = 0;
        for(let i = 0; i < arr.length; i++){
          if(nums.indexOf(arr[i]) === -1){   // nums中不包含arr[i]
            nums.push(arr[i]);
            max = nums.length > max ? nums.length : max;
          }
          else{
            nums = [];
            break;
          }
        }
        resMax = max > resMax ? max : resMax;
        arr.shift();
        index++;
      }
      return resMax;
    }

(2)

算法 文章被收录于专栏

JavaScript算法

全部评论

相关推荐

码农索隆:想看offer细节
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务