版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Android_chunhui/article/details/89266175
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.
-
思路 1
在遍历字符串过程中,碰到重复字符就意味着新的不重复子串的开始。所以我们要定义两个变量:len记录最长子串的长度,left记录当前子串的起始位置。 -
思路 2