3. 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.
题意:
从一个字符串中查找子串,但是这个子串中不能包含重复的字符,并且要找出最长的不重字符复子串。
思路:
利用字符映射表来记录此字符之前(包括字符本身)有多少个元素,然后再利用一个元素来记录,此元素对应的之前重复的那个元素的之前的元素个数。
1 | class Solution |
Java Code:
1 | class Solution { |