TIme limit exceed..


  • 0
    P

    The below code working properly in my systemm..for various inputs..can any one tell me whta goes wrong here..


       int counter = 0;  // Inialize the counter
    		int i=0,j=0;
    		while(i<=s.length()){
    			int n = s.indexOf("("); //Find the index of (
    			if(n==-1){
    				break; //No index found break
    			}
    			if(n == 0){
    				s=s.substring(j,s.length());
    				n = s.indexOf(")");  //Find the index (
    				if(n==0){
    					s=s.substring(j,s.length()); //If ( and ) found in first and second pos..remove those two 
    					counter++; //Increment the counter
    				}else if(n == -1){
    					if(counter==0){
    						counter =0;
    					}
    				    break;
    				}else if(n > 0){
    					s=s.substring(0, n-1)+s.substring(n+1, s.length()); //If ) found in position somewhere ..remove ) and ( from that position.
    					System.out.println(""+s);
    					counter++;
    				}
    			}else if (n>0){
    	        	s=s.substring(n,s.length());
    	        	n=s.indexOf(")");
    			}
    		}
    


  • 0
    S

    Could you please format your code and show us the test case that yields TLE?


  • 0
    S

    Remove System.out.println(""+s);

    Read OJ FAQ and pay attention on this question

    Am I allowed to print something to stdout?


Log in to reply
 

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