I would use a hash to count how often the numbers between 0 and sum/10 show up. then go through the has to see if we have two that match. it is O(n^2) also, and doesn't work if sum is large.

int[] findSum(int[] nums, int sum) {

int[] hash = new int[sum+1];

//count how many numbers

for (int i=0; i 0) && (hash[sum-i]>0)) {

return new int[] {i, sum-i};

}

}

return null;

}

My first guess is something like the following, where 10 would be passed as the sum parameter:

int[] findSum(int[] nums, int sum){

int[] pair = null;

for(int i = 0; i < nums.length; i++){

int a = nums[i];

int target = sum - a;

for(int j = 0; j < nums.length; j++){

if(nums[ j ] == target){

pair = new int[2];

pair[0] = a;

pair[1] = target;

return pair;

}

}

}

return pair; // returns null if no suitable pair found

}

}