45ms. accepted. java. different method. Is there some advice?


  • 0
    M
    This post is deleted!

  • 0
    L

    nice idea to avoid judging empty string..and similar to mine:)

    public class Solution {
    public int lengthOfLongestSubstring(String s) {
    int start=0;
    int end=1;
    int max=1;
    int len=s.length();
    if(len==0)
    return 0;
    while(end<len){
    int pos=s.substring(start,end).indexOf(s.charAt(end));
    if(pos!=-1){
    start+=pos+1;
    end++;
    }else{
    end++;
    }
    max=Math.max(max,end-start);
    }
    return max;
    }
    }


Log in to reply
 

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