algorithm icon indicating copy to clipboard operation
algorithm copied to clipboard

3. 无重复字符的最长子串

Open JesseZhao1990 opened this issue 6 years ago • 0 comments

image

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function(s) {
    let arr = s.split('');
    let max = 0;
    let temp = [];
    for(let i=0,j=0;j<arr.length;){
      if(arr[j] != undefined && !temp.includes(arr[j])){
        temp.push(arr[j])
        j++
      }else{
        i++
        temp = arr.slice(i,j);
      }
        max = max > temp.length ? max : temp.length;
    }

    return max;
    
};

JesseZhao1990 avatar Oct 19 '19 13:10 JesseZhao1990