123456789101112131415161718 |
- package main
- func lengthOfLongestSubstring(s string) int {
- max := 0
- for i := 0; i < len(s); i++ {
- // a map stores all runes showed up after index i
- m := map[byte]int{s[i]: 1}
- for j := i + 1; j < len(s); j++ {
- if m[s[j]] == 1 {
- max = maxInt(len(m), max)
- break
- }
- m[s[j]] = 1
- }
- max = maxInt(len(m), max)
- }
- return max
- }
|