func lengthOfLongestSubstring(s string) (ans int) {
    window := [128]bool{}
    left := 0
    for right, v := range s {
        for window[v] {
            window[s[left]] = false
            left++
        }
        window[v] = true
        ans = max(ans, right-left+1)
    }
    return
}

func max(a, b int) int {
    if b > a {
        return b
    }
    return a
}
Last modification:May 28, 2024
如果觉得我的文章对你有用,请收藏本站