func lengthOfLongestSubstring(s string) int {
arr := strings.Split(s, "")
tempArr := []string{}
max := 0
curr := 0
for _, val := range arr {
index, contain := contains(tempArr, val)
if !contain {
tempArr = append(tempArr, val)
curr += 1
} else {
tempArr = tempArr[index+1:]
tempArr = append(tempArr, val)
curr = curr - index
}
max = Max(max, curr)
}
return max
}
func contains(arr []string, val string) (int, bool) {
for i, v := range arr {
if v == val {
return i, true
}
}
return -1, false
}
LeetCode——最长不重复子串
猜你喜欢
转载自blog.csdn.net/liyuxing6639801/article/details/105624953
今日推荐
周排行