21 lines
412 B
Go
21 lines
412 B
Go
// Package q3 implements a solution for https://leetcode.com/problems/longest-substring-without-repeating-characters/
|
|
package q3
|
|
|
|
func lengthOfLongestSubstring(s string) int {
|
|
seen := make([]bool, 256)
|
|
maxLen := 0
|
|
|
|
l := 0
|
|
for r := range len(s) {
|
|
c := s[r]
|
|
for seen[c] {
|
|
seen[s[l]] = false
|
|
l++
|
|
}
|
|
seen[c] = true
|
|
maxLen = max(maxLen, r-l+1)
|
|
}
|
|
return maxLen
|
|
}
|
|
|
|
var _ = lengthOfLongestSubstring
|