question:
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
題目翻譯:
給定一個字符串,找到最長無重復(fù)字符的子串的長度。例如,"abcabcbb"的最長無重復(fù)字符的子串為"abc”,它的長度為3。"bbbbb”的最長子串為"b”,長度為1。
分析:
注意特殊情況的考慮:
1 只有1個字符時,直接返回1
2 當(dāng)?shù)竭_字符串結(jié)尾時,要把此時的長度考慮進去
代碼如下:
