Why the length of the longest no-repeating char. substring in "qwnfenpglqdq" is 8!!!


  • 0
    G

    public class Solution {
    public int lengthOfLongestSubstring(String s) {
    if(s.length() < 2) return s.length();
    int[] value = new int[256];
    for (int i = 0; i < 256; i++)
    value[i] = -1;
    //memset(value, -1, sizeof(value));
    int last_start = 0;
    int current_length = 0;
    int max = 0;
    char ch;
    for(int i = 0; i < s.length(); i++)
    {
    ch = s.charAt(i);
    if(value[ch] == -1)
    {
    current_length ++;
    value[ch] = i;
    }
    else
    {
    if(last_start <= value[ch])
    {
    current_length = i - value[ch];
    last_start = value[ch] + 1;
    value[ch] = i;
    }
    else
    current_length++;
    }
    if(current_length > max)
    max = current_length;
    }
    return max;
    }
    }


  • 0
    W

    The longest no-repeating substring is "fenpglqd", the length is 8


  • 0
    K

    No, I think it is 9
    "qwnfenpgl" or
    "wnfenpglp"

    It is because the length is 1 instead of 0 for "bbb".


  • 0
    L
    This post is deleted!

  • 0
    L

    wnfen nfen n..n
    hahahahahahaha .............


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.