Longest Substring Without Repeating Characters

func lengthOfLongestSubstring(s string) int {

    var sMap []rune
    for _,v := range s{
        sMap = append(sMap,v)
    }
        if len(sMap) == 0 {
            return 0
        }
    //max := 0
    headPoint := 0
    tailPoint := 0
    maxHead := 0
    maxTail := 0

    for k,_ := range sMap{
        max := maxTail-maxHead+1
        tailPoint = k
        change := false
        for i:=headPoint;is2{
                    if s1>max{
                        maxHead = headPoint
                        maxTail = i
                    }
                }else{
                    if s2>=max{
                        maxHead = i+1
                        maxTail = tailPoint
                    }
                }
                headPoint = i+1
                change = true

            }
        }

        if !change && k-1 == maxTail{
            maxTail = k
        }
        if(tailPoint-headPoint) >= (maxTail-maxHead){
            maxTail = tailPoint
            maxHead = headPoint
        }
        fmt.Println(headPoint,tailPoint,maxHead,maxTail)

    }

    return maxTail-maxHead+1


}

你可能感兴趣的:(Longest Substring Without Repeating Characters)