Skip to content

Commit 092c17d

Browse files
committed
small refactor for clarity
1 parent 83f6f7d commit 092c17d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

leetcode/0003.longest_substring_without_repeating_characters/3.longest_susbtring_without_repeating.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package data_structures_algorithms
22

33
func lengthOfLongestSubstring(s string) int {
4-
right, left, res := 0, 0, 0
4+
left, right, res := 0, 0, 0
55
indexes := make(map[byte]int, len(s))
6-
for left < len(s) {
7-
if index, ok := indexes[s[left]]; ok && index >= right {
8-
right = index + 1
6+
for right < len(s) {
7+
if index, ok := indexes[s[right]]; ok && index >= left {
8+
left = index + 1
99
}
10-
indexes[s[left]] = left
11-
left++
12-
res = max(res, left-right)
10+
indexes[s[right]] = right
11+
right++
12+
res = max(res, right-left)
1313
}
1414
return res
1515
}

0 commit comments

Comments
 (0)