Skip to content

Instantly share code, notes, and snippets.

@lotabout
Created March 20, 2014 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotabout/9658412 to your computer and use it in GitHub Desktop.
Save lotabout/9658412 to your computer and use it in GitHub Desktop.
Liu, Shi's solution of permutation of 7 number.
package demo;
import java.util.ArrayList;
import java.util.List;
public class demo {
static List<String> cout(List<String> one,String str){
List<String> t = new ArrayList<String>();
for(int i =0;i<one.size();i++){
char[] s = one.get(i).toCharArray();
t.add(str+one.get(i));
for(int j=0;j<s.length;j++){
String st = one.get(i).substring(0, j+1);
String sst = one.get(i).substring(j+1);
t.add(st+str+sst);
}
}
return t;
}
public static void main(String[] args) {
String temp[] = {"1","2","3","4","5","6","7"};
List<String> s = new ArrayList<String>();
s.add(temp[0]);
for(int i = 1;i<temp.length;i++)
s = cout(s,temp[i]);
for(int i = 0;i<s.size();i++)
System.out.println((i+1)+"--"+s.get(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment