¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Combination Sum

Suhas S Inglés 1 ficha

Fichas del conjunto (1)

  1. 1Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited number of times. [2, 3, 6, 7] and target 7, [ [7], [2, 2, 3] ]public List> combinationSum(int[] candidates, int target) {
    ArrayList> list = new ArrayList<>();
    Arrays.sort(candidates);
    sum_up_recursive(list,new ArrayList<>(),candidates,target,0);
    return list;
    }
    private void sum_up_recursive(ArrayList> list, ArrayList tempList, int[] nums, int remain, int start ){
    if(remain < 0 ) return;
    if(remain == 0) list.add(new ArrayList<>(tempList));
    else{
    for(int i = start; i start && nums[i] == nums[i-1]) continue;//In case of duplicates
    tempList.add(nums[i]);
    sum_up_recursive(list, tempList, nums, remain - nums[i], i);//If you want the same number to be counted for getting the nummber else put i+1
    tempList.remove(tempList.size()-1);
    }
    }
    }

Información

Descripción
Fichas sobre Combination Sum, creado por Suhas S el 20/03/2018.
Creado por
Suhas S
Visitas
2
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?