ThreeSum Solution in Java
ThreeSum in java. Given an array nums of n integers , are there elements a , b , c in nums such that a + b + c = 0 Find all unique triplets in the array which gives the sum of zero. Note the solution set must not contain duplicate triplets. Example : Given array nums = [ -1 , 0 , 1 , 2 , -1 , -4 ] A solution set is : [ [-1 , 0 , 1], [ -1, -1, 2], ] import java.util.*; class ThreeSum { static List<List<Integer>> calculate(int[] arr) { if(arr == null || arr.length < 3) { return Collections.emptyList(); } int n = arr.length; List<List<Integer>> list = new ArrayList<List<Integer>>(); Map<Integer,Integer> map = new HashMap<>(); for(int i=0;i<n-2;i++) { int first = arr[i]; for(int j=i+1;j<n;j++) { int remain = first+arr[j]; remain = (remain<0)?Ma...