[JAVA] Still exceeded time limit, why?


  • 0
    L
        int from = 0;
    	int to = 1;
    	int maxLength = 1;
    	int tmpLength = 1;
    	int count = s.length();
    	
    	char[] array = s.toCharArray();
    	
    	while(to<count){
    		String candidate = s.substring(from, to);
    		String next = String.valueOf(array[to]);
    		int index = candidate.indexOf(next);
    		if(-1!=index){
    			from = index+1;
    			maxLength = tmpLength>maxLength?tmpLength:maxLength;
    			tmpLength = 0;
    		}else{
    			tmpLength++;
    		}
    		to++;
    	}
    	return maxLength;

  • 0
    A

    I get the same error. On my i5 machine it takes 0.017s to execute.


Log in to reply
 

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