LeetCode 3. Longest Substring Without Repeating Characters [Sliding Window, Two-Pointers]
Problems:
Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
-Summary-
1. Set two-pointer for string s. (pointer1 and pointer2)
2. - If the current character of the s is not in the dictionary, add the character to the dictionary. ( Update maximum length and Move the pointer2)
- If the current character is already in the dictionary, we pop and move the pointer1.
3. After loop, return maxLength.
Below is a good article on the sliding-window problems.
https://medium.com/outco/how-to-solve-sliding-window-problems-28d67601a66
How to Solve Sliding Window Problems
Sliding Window problems are a type of problem that frequently gets asked during software engineering interviews and one we teach at Outco…
medium.com
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]