MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / lengthOfLongestSubstring

Function lengthOfLongestSubstring

tasks/3.go:11–29  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

9}
10
11func lengthOfLongestSubstring(s string) int {
12 maxLen := 0
13 mp := make([]int, 128)
14 for i := range mp {
15 mp[i] = -1
16 }
17 windowStart := -1
18
19 for windowEnd, r := range s {
20 if mp[r] > windowStart {
21 windowStart = mp[r]
22 }
23 mp[r] = windowEnd
24 if maxLen < windowEnd-windowStart {
25 maxLen = windowEnd - windowStart
26 }
27 }
28 return maxLen
29}
30
31// func lengthOfLongestSubstring(s string) int {
32// counter := 0

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected