Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
combination sum (variation)
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { //[2,3,5,6,7] public static List<Integer> subsetSum(int[] candidates,int target){ List<Integer> out = new ArrayList<>(); helper(candidates,target,out,0); return out; } public static boolean helper(int[] candidates,int target,List<Integer> lst,int index){ if(target==0) return true; if(target<0) return false; for(int i=index;i<candidates.length;i++){ lst.add(i); if(!helper(candidates,target-candidates[i],lst,i+1)) lst.remove(lst.size()-1); else return true; } return false; } public static void main(String args[]) { System.out.println("Hello, World!"); List<Integer> lst = subsetSum(new int[]{2,3,5,6},7); for(Integer i:lst){ System.out.print(i+" "); } } }
run
|
edit
|
history
|
help
0
pk3
pow x^n
JAVA regex for only allow numbers
Info by dfs
exp.1A
Check Input
1
java polymorhism
Job and Trait Generator
Counter.java