You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Example 1:
Example 2:
Example 3:
题意:已知一个字符串,求该字符串的无重复字符的最长子串长度。
算法思路:
char_map
;word
;i
和指针begin
)指向字符串的第一个字符;result
;char_map
,记录字符数量;word
中没有出现过该字符:对word
尾部添加字符并检查result
是否需要更新;begin
指针向前移动,更新char_map
中的字符数量,直到字符s[i]
数量为1,更新word
,将word
赋值为begin
和i
之间的 子串。在整个过程之间,使用
begin
和i
维护一个窗口,该窗口中的子串满足题目中的条件,窗口线性向前滑动,时间复杂度为O(n)
。The text was updated successfully, but these errors were encountered: