File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 2
2
package main
3
3
4
4
func lengthOfLongestSubstring (s string ) int {
5
- runeS := []rune (s )
6
- maxLen := 0
7
- head := 0
8
- using := make (map [rune ]struct {})
9
- for tail := 0 ; tail < len (runeS ); tail ++ {
10
- if _ , ok := using [runeS [tail ]]; ok {
11
- for runeS [head ] != runeS [tail ] {
12
- delete (using , runeS [head ])
5
+ maxLen , head := 0 , 0
6
+ using := make (map [byte ]struct {})
7
+ for tail := range s {
8
+ if _ , ok := using [s [tail ]]; ok {
9
+ for s [head ] != s [tail ] {
10
+ delete (using , s [head ])
13
11
head ++
14
12
}
15
13
head ++
16
14
} else {
17
- using [runeS [tail ]] = struct {}{}
15
+ using [s [tail ]] = struct {}{}
18
16
}
19
- substring := runeS [head : tail + 1 ]
20
- maxLen = max (maxLen , len (substring ))
17
+ maxLen = max (maxLen , tail - head + 1 )
21
18
}
22
19
return maxLen
23
20
}
You can’t perform that action at this time.
0 commit comments