Last active
March 21, 2020 03:24
-
-
Save varvir/8aa16d033ac6b7caaf8d0bdb6ee01ad3 to your computer and use it in GitHub Desktop.
Latest version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<List<Integer>> combination(int[] n, int r){ | |
List<List<Integer>> ret = new ArrayList<>(); | |
combination(new ArrayList<>(), n, r, ret); | |
System.out.println(ret); | |
return ret; | |
} | |
void combination(List<Integer> prefix, int[] n, int r, List<List<Integer>> result){ | |
if(r==0) result.add(prefix); | |
else { | |
for(int k=0; k<=n.length-r; k++){ | |
ArrayList<Integer> prefixcopy = new ArrayList<>(prefix); | |
prefixcopy.add(n[k]); | |
combination(prefixcopy, Arrays.copyOfRange(n, k+1, n.length), r-1, result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment