sony面试题
把一个数组里的数组合全部列出了 比如1 2 列出来为 1, 2 ,12,21,
代码是:
public static void main(String[] args) throws Exception {
String[] array = new String[] {
"1 ", "2 ", "3 ", "4 "
};
listAll(Arrays.asList(array), " ");
}
public static void listAll(List candidate, String prefix) {
// if (candidate.isEmpty()) {
System.out.println(prefix);
// }
for (int i = 0; i < candidate.size(); i++) {
List temp = new LinkedList(candidate);
listAll(temp, prefix + temp.remove(i));
}
}
=====输出=====
1
12
123
1234
124
1243
13
132
1324
134
1342