美文网首页
3 longest substring without repe

3 longest substring without repe

作者: Fei_JOB | 来源:发表于2017-10-19 06:55 被阅读0次

    1. sliding window:  longest = end - start + 1;

    cases need to cover: 

    "abcabcabcdd" contains repeated number

    "abc" no repeated character: essentially return the length of the string.

    for every end, we can get the longest substring ending with s.charAt(end), so using the hash array to record how many times the character appeared already. When (hash[endChar]) > 1, which means the current end is a repeated character, the start is not valid for this substring, we need to move start until hash[endChar] <= 1 again, then end - start + 1 is the length valid for current end. 

    scan along, when end reached the boundary, we got the longest length.

    相关文章

      网友评论

          本文标题:3 longest substring without repe

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