I have checked my code on eclipse IDE and in the Leet Debugger . After submitting my finished code I get an Wrong Prompted for a testcase.But my code passes the test when run in Debug mode.
This Issue is preventing my code To get submitted into Leet.This is a Bug.I tried several times but after wasting ample of time have to post this issue.
class Solution {
static List lst=new ArrayList();
static int target=3;
int closest=0;
public int threeSumClosest(int[] nums, int target) {
combinations2(nums,3,0,new int[3]);
for(int i:lst) {
if(Math.abs(target-i)==0) {
System.out.println(i);
return i;
}else {
if(closest == 0 ) {
closest= i;
}else {
if(closest>i)
closest=i;
}
}
}
System.out.println(closest);
return closest;
}
static void combinations2(int[] arr, int len, int startPosition, int[] result){
if (len == 0){
int sum=0;
for(int i : result)
sum=sum+i;
lst.add(sum);
//System.out.println(Arrays.toString(result));
return;
}
for (int i = startPosition; i <= arr.length-len; i++){
result[result.length - len] = arr[i];
combinations2(arr, len-1, i+1, result);
}
} }
This Solution is in JAVA.