File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
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 )
5
6
maxLen := 0
6
7
head := 0
7
- m := make (map [rune ]struct {})
8
- for tail := 1 ; tail <= len (s ); tail ++ {
9
- if _ , ok := m [ rune ( s [tail - 1 ]) ]; ok {
10
- for s [head ] != s [tail - 1 ] {
11
- delete (m , rune ( s [head ]) )
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 ])
12
13
head ++
13
14
}
14
15
head ++
15
16
} else {
16
- m [ rune ( s [tail - 1 ]) ] = struct {}{}
17
+ using [ runeS [tail ] ] = struct {}{}
17
18
}
18
- substring := s [head : tail ]
19
+ substring := runeS [head : tail + 1 ]
19
20
maxLen = max (maxLen , len (substring ))
20
21
}
21
22
return maxLen
You can’t perform that action at this time.
0 commit comments