Created
March 21, 2020 04:13
-
-
Save varvir/808739dd49f59fb0bcb29ea2fcbb6441 to your computer and use it in GitHub Desktop.
int[]로 주어질 때
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>> permutation(int[] n){ | |
List<List<Integer>> ret = new ArrayList<>(); | |
permutation(new ArrayList<>(), n, ret); | |
System.out.println(ret.size()); | |
return ret; | |
} | |
void permutation(List<Integer> prefix, int[] n, List<List<Integer>> result){ | |
if(n.length==0){ | |
result.add(prefix); | |
} else { | |
for(int k=0; k<n.length; k++){ | |
var tmp = new ArrayList<Integer>(prefix); | |
tmp.add(n[k]); | |
int[] next = Stream.concat(Arrays.stream(Arrays.copyOfRange(n, 0, k)).boxed(), | |
Arrays.stream(Arrays.copyOfRange(n, k+1, n.length)).boxed()) | |
.mapToInt(i->i).toArray(); | |
permutation(tmp, next, result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment