Skip to content

Commit 5b61f41

Browse files
committed
add step4 for Longest Substring Without Repeating Characters
1 parent 65fb184 commit 5b61f41

File tree

1 file changed

+14
-0
lines changed
  • pullrequests/longest_substring_without_repeating_characters

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//lint:file-ignore U1000 Ignore all unused code
2+
package longestsubstringwithoutrepeatingcharacters
3+
4+
func lengthOfLongestSubstring_step4(s string) int {
5+
maxLength, left, seen := 0, 0, make(map[rune]int)
6+
for right, r := range s {
7+
if lastIndex, ok := seen[r]; ok && lastIndex >= left {
8+
left = lastIndex + 1
9+
}
10+
seen[r] = right
11+
maxLength = max(maxLength, right-left+1)
12+
}
13+
return maxLength
14+
}

0 commit comments

Comments
 (0)