package norepeat func max(x, y int) int { if x > y { return x } return y } func lengthOfLongestSubstring(s string) int { positions := map[byte]int{} longest := 0 for i := 0; i < len(s); i++ { char := s[i] pos, exists := positions[char] positions[char] = i longest = max(longest, len(positions)) if exists { positions = map[byte]int{} i = pos } } return longest } func LengthOfLongestSubstring(s string) int { return lengthOfLongestSubstring(s) }