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]
'LeetCode > Problems' 카테고리의 다른 글
LeetCode 34. Find First and Last Position of Element in Sorted Array [Binary Search] (0) | 2020.06.13 |
---|---|
5. Longest Palindromic Substring [Strings, dynamic programming] (0) | 2020.06.11 |
LeetCode 2. Add Two Numbers [Linked List] (0) | 2020.06.09 |
LeetCode 21. Merge Two Sorted Lists (0) | 2020.06.01 |
LeetCode 206. Reverse Linked List (0) | 2020.06.01 |
댓글