TLE during test but accepted in OJ


  • 0
    L

    Simple code as follows.

    	public int triangleNumber( int[] nums )
    	{
    		int count = 0;
    		Arrays.sort( nums );
    		for ( int i = 0; i < nums.length - 2; i++ )
    		{
    			for ( int j = i + 1; j < nums.length - 1; j++ )
    			{
    				int a = nums[i], b = nums[j], k = j + 1, l = nums.length - 1;
    				while ( k < nums.length && a + b > nums[k] )
    					k++;
    				count += k - 1 - j;
    			}
    		}
    		return count;
         }
    

    I've submitted only once during contest, and it gave me TLE. couldn't figure out a better way to solve this problem.

    Just checked editorial, and didn't seem that different with the third solution.

    Now I just tried it on non-test OJ, and was accepted..

    Just kinda feel frustrated. I could have finished test in 60 minute then. (滑稽)


Log in to reply
 

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