Created
June 1, 2017 12:41
-
-
Save danivijay/b8fe59e496434e27205666e4a558e8be to your computer and use it in GitHub Desktop.
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
package com.google.challenges; | |
public class Answer { | |
public static int answer(int[] l) { | |
// Your code goes here. | |
} | |
} |
To find all permutations of an array :
public class Permute{
static void permute(java.util.List<Integer> arr, int k){
for(int i = k; i < arr.size(); i++){
java.util.Collections.swap(arr, i, k);
permute(arr, k+1);
java.util.Collections.swap(arr, k, i);
}
if (k == arr.size() -1){
System.out.println(java.util.Arrays.toString(arr.toArray()));
}
}
public static void main(String[] args){
Permute.permute(java.util.Arrays.asList(3,4,6,2,1), 0);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer https://github.com/danivijay/code_challenges for logic