LeetCode 3 - length of longest S

2018-05-15  本文已影响0人  thousand_

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.

题目翻译:

给定一个字符串,找到最长无重复字符的子串的长度。例如,"abcabcbb"的最长无重复字符的子串为"abc”,它的长度为3。"bbbbb”的最长子串为"b”,长度为1。

分析:

注意特殊情况的考虑:

1 只有1个字符时,直接返回1

2 当到达字符串结尾时,要把此时的长度考虑进去

代码如下:

上一篇下一篇

猜你喜欢

热点阅读