Skip to content

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

@JesseZhao1990

Description

@JesseZhao1990

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;
    
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions