Q3. Longest Substring Without Repeating Characters
Last updated
Was this helpful?
Last updated
Was this helpful?
直达:
Given a string, find the length of thelongest substringwithout 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 asubstring,"pwke"
is asubsequenceand not a substring.
用哈希表存储每个元素的下标(hash[s[i]] = i
)如重复,可用新的下标覆盖旧的下标。遍历字符串,如果哈希表中不存在该字符,