字符串中不含有重复字符的最长子串

给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。

Input: 'abcabcbb'
Output: 3

Input: 'au'
Output: 2

Input: ''
Output: 0

Input: ' '
Output: 1

思路:双指针

var lengthOfLongestSubstring = function(s) {
  let res = 0;
  let len = s.length;
  let i = 0;
  for (let j=i; j= 0) {
      res = Math.max(res, str.length);
      i += index + 1;
    } else if (j === len-1) {
      res = Math.max(res, len-i);
    }
  }
  return res;
};

你可能感兴趣的:(字符串中不含有重复字符的最长子串)