Your title here...Given n unique integers, number k (1<=k<=n) and target.
Find all possible k integers where their sum is target.
public class Solution { /* * @param A: an integer array * @param k: a postive integer <= length(A) * @param targer: an integer * @return: A list of lists of integer */ public List<List<Integer>> kSumII(int[] A, int k, int target) { // write your code here List<List<Integer>> resultList = new ArrayList<>(); if (A == null || A.length == 0 || k == 0 || k > A.length) { List<Integer> childList = new ArrayList<>(); resultList.add(childList); return resultList; } if (k == 1) { for (int i = 0; i < A.length; i++) { if (target == A[i]) { List<Integer> childList = new ArrayList<>(); childList.add(A[i]); resultList.add(childList); break; } } return resultList; } else { while (A.length >= 1) { int num = A[0]; A = Arrays.copyOfRange(A, 1, A.length); List<List<Integer>> list = kSumII(A, k - 1, target - num); for (List<Integer> childList : list) { if (!childList.isEmpty()) { childList.add(num); resultList.add(childList); } } } return resultList; } } }