← 返回 cisco 的题目列表Return the Longest Substring Without Repeating Characters
类型:online_judge
Given a string s, find and return the longest contiguous substring that contains no repeated characters. Return the substring itself rather than its length.
If multiple longest valid substrings exist, return the leftmost one (the one with the smallest starting index).
The string may contain letters, digits, spaces, and other ASCII characters.
Examples
Input: s = "abcabcbb"
Output: "abc"
Explanation: "abc" is the longest substring without repeating characters.
Input: s = "pwwkew"
Output: "wke"
Explanation: "wke" is the longest substring without repeating characters; "pwke" is not contiguous.
Constraints
0 <= len(s) <= 10^5
Target time complexity: O(n)
Target extra space complexity: O(min(n, alphabet size))
Example
Input
abcabcbb
Output
abc