当前位置 博文首页 > 无限迭代中......:LeetCode 3 无重复字符的最长子串
https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
Go 版本
func lengthOfLongestSubstring(s string) int {
// 哈希集合,记录每个字符是否出现过
var m [128]int
n := len(s)
rk, ans := 0, 0
for i := 0; i < n; i++ {
if m[s[i]] > rk {
if ans < i - rk {
ans = i - rk
}
rk = m[s[i]]
}
m[s[i]] = i + 1
}
if ans < n - rk {
return n - rk
}
return ans
}
无重复字符的最长子串-官方题解
cs