Beats 95% 16ms Java clean solution, easy understand

  • 0
    List<List<Integer>> res;
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
    	res = new ArrayList<List<Integer>>();
    	helper(new ArrayList<Integer>(), candidates, 0, target);
    	return res;
    private void helper(List<Integer> list, int[] candidates, int cur, int remain) {
    	if (remain == 0) {res.add(new ArrayList<Integer>(list)); return;}
    	else if (remain < 0 ) return;
    	for (int i = cur; i < candidates.length; i++) {
    		if (candidates[i] > remain) continue;
    		helper(list, candidates, i, remain-candidates[i]);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.