Created
December 26, 2019 10:55
-
-
Save chaudharisuresh997/b7c2e055081bb1a0741eff4bf06e972e to your computer and use it in GitHub Desktop.
Permutation is repeating list in output.
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
import java.util.ArrayList; | |
public class Solution{ | |
public ArrayList<ArrayList<Integer>> permute(ArrayList<Integer> A) { | |
ArrayList<ArrayList<Integer>> big=new ArrayList<ArrayList<Integer>>(); | |
permute(big,A,0); | |
return big; | |
} | |
public void permute(ArrayList<ArrayList<Integer>> big,ArrayList<Integer> A,int inc){ | |
if(inc>=A.size()-1){ | |
big.add(new ArrayList<Integer>(A)); | |
} | |
for(int i=inc;i<A.size();i++){ | |
swap(A,inc,i); | |
permute(big,A,inc+1); | |
swap(A,inc,i); | |
} | |
} | |
public void swap(ArrayList<Integer> A,int start,int end){ | |
int temp=A.get(start); | |
A.set(start,A.get(end)); | |
A.set(end,temp); | |
} | |
public static void main(String[] args) { | |
ArrayList<Integer> A=new ArrayList<Integer>(); | |
A.add(1); | |
A.add(2); | |
A.add(3); | |
A.add(4); | |
ArrayList<ArrayList<Integer>> rotatedArrays=new ArrayList<ArrayList<Integer>>(); | |
new Solution().permute(A); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment