**Can you guys please help me with this problem?**

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? This is what I have so far, but it doesn't work, however, I'm sure there are better approaches too, any tips or suggestions are greatly appreciated. Thanks:)

` public static int[][]threeSum(int[] nums, int target){ Hashtable<Integer, Integer> values = new Hashtable<Integer, Integer>(); for(int cnt=0; cnt < nums.length; cnt++){ values.put(nums[cnt], cnt); } int[][] list = new int[4][4]; int count = 0; for(int cnt=0; cnt < nums.length; cnt++){ for(int cnt1=cnt+1; cnt1 < nums.length; cnt1++){ int n = nums[cnt]+nums[cnt1]; if (count >3){break;} if (values.get(target-n)!=null){ list[count][0]=cnt; list[count][1]=cnt1; list[count][2]=values.get(target-n); count++; } } } return list; } `

Submitted July 12, 2017 at 03:08AM by limbwal

via reddit http://ift.tt/2uc48Uj

### Like this:

Like Loading...

*Related*