Skip to content

Instantly share code, notes, and snippets.

@Wooking0310
Created January 1, 2016 15:57
Show Gist options
  • Save Wooking0310/ff34cff2520eee3e2d46 to your computer and use it in GitHub Desktop.
Save Wooking0310/ff34cff2520eee3e2d46 to your computer and use it in GitHub Desktop.
public static void perm(String head, String input, int size, ArrayList<String> arr) throws Exception{
// Random random = new Random();
if (input.length() <= 1) {
arr.add(head+input);
// for(int i = 0; i < size; i++) {
// int num = random.nextInt(size-1)+1;
// System.out.println(arr.get(num));
// arr.remove(num);
// size--;
return;
}
for (int i = 0; i < input.length(); i++) {
String newStr = input.substring(0, i) + input.substring(i + 1); // substring(자를 위치 첨자, 첨자에서 자를만큼의 길이) or substring(자를 위치 첨자)
perm(head + input.charAt(i), newStr, size, arr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment