美文网首页
LeetCode 3 - length of longest S

LeetCode 3 - length of longest S

作者: thousand_ | 来源:发表于2018-05-15 16:30 被阅读0次

    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 当到达字符串结尾时,要把此时的长度考虑进去

    代码如下:

    相关文章

      网友评论

          本文标题:LeetCode 3 - length of longest S

          本文链接:https://www.haomeiwen.com/subject/nbhydftx.html