1 Star 0 Fork 1

dllearn/geektime-algorithm-learn

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
f.go 600 Bytes
Copy Edit Raw Blame History
dryyun authored 2022-05-11 01:23 +08:00 . 0003
package longestsubstringwithoutrepeatingcharacters
// 3. 无重复字符的最长子串
// https://leetcode.cn/problems/longest-substring-without-repeating-characters/
func lengthOfLongestSubstring(s string) int {
if s == "" {
return 0
}
mp := make(map[byte]int, 0)
ml := 1
start := 0
bs := []byte(s)
for i, v := range bs {
if _, ok := mp[v]; ok {
nStart := mp[v] + 1
// 删除之前的所有内容
for j := start; j < nStart; j++ {
delete(mp, bs[j])
}
start = nStart
mp[v] = i
} else {
mp[v] = i
if ml < len(mp) {
ml = len(mp)
}
}
}
return ml
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dllearn/geektime-algorithm-learn.git
git@gitee.com:dllearn/geektime-algorithm-learn.git
dllearn
geektime-algorithm-learn
geektime-algorithm-learn
55fa3f222b36

Search