My java solution timeout,can optimize on it?


  • 0
    S
    public static int[] twoSum(int[] numbers, int target) {
    		int m = 0;
    		int n = 1;
    		int outSum[] = new int[2];
    			while (m < numbers.length) {
    				if (n>numbers.length-1) {
    					m++;
    					n=m+1;
    				} else {
    					if (numbers[m] + numbers[n] == target) {
    						outSum[0] = m + 1;
    						outSum[1] = n + 1;
    						m = numbers.length;
    					} else {
    						n++;
    					}
    				}
    			return outSum;
    		}
    	}

Log in to reply
 

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