Created
March 20, 2014 06:34
-
-
Save lotabout/9658412 to your computer and use it in GitHub Desktop.
Liu, Shi's solution of permutation of 7 number.
This file contains 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 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