Leetcode 3[medium]--- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb"
, the answer is "abc"
, which the length is 3.
Given "bbbbb"
, the answer is "b"
, with the length of 1.
Given "pwwkew"
, 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.
思路:题意简单,找到给定的string中没有重复字符的最长的亚string。
用字典的key和value记录下每个字符对应的位置,后出现的重复字符的位置会覆盖掉之前出现的。start记录下相同字符的上一次出现位置+1