3. Longest Substring Without Repeating Characters
# Medium
Solution 1:
Know the longest length of first i
chars, then the longest length of first i+1
chars is max(longest[i]
, longest length from i+1
to 0
).
Solution 2:
Keep a sliding window by left and right pointers, left pointer doesn't move, right pointer moves. If s[right] is duplicated in sliding window, s[left] is removed from the set pf sliding window and left pointer moves one step, repeat this step until s[right] is not duplicated in sliding window. At the same time, record the longest length of the sliding window.
Last updated
Was this helpful?