当前位置:网站首页>Full Permutation Code (recursive writing)
Full Permutation Code (recursive writing)
2022-07-05 05:38:00 【Java full stack R & D Alliance】
The code is as follows :
public static List<String> getSubstring(String[] words) {
if(words.length==1){
return Arrays.asList(words);
}
List<String> resultList = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
String[] strings = Arrays.copyOf(words, words.length);
strings = changeArray(strings, i);
List<String> stringList = getSubstring(strings);
for (String str : stringList) {
resultList.add(words[i] + str);
}
}
return resultList;
}
public static String[] changeArray(String[] words, int i) {
for (int k = i; k < words.length - 1; k++) {
words[k] = words[k + 1];
}
return Arrays.copyOf(words, words.length - 1);
}
If you test
String[] words = {
"1", "2", "3"};
List<String> substring = getSubstring(words);
System.out.println(substring);
Print the results :
边栏推荐
猜你喜欢
Sword finger offer 09 Implementing queues with two stacks
Acwing 4300. Two operations
Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
Sword finger offer 05 Replace spaces
EOJ 2021.10 E. XOR tree
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
YOLOv5-Shufflenetv2
Sword finger offer 06 Print linked list from beginning to end
On-off and on-off of quality system construction
Yolov5 ajouter un mécanisme d'attention
随机推荐
Sword finger offer 09 Implementing queues with two stacks
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
【Jailhouse 文章】Performance measurements for hypervisors on embedded ARM processors
注解与反射
shared_ Repeated release heap object of PTR hidden danger
CF1637E Best Pair
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Reflection summary of Haut OJ freshmen on Wednesday
全排列的代码 (递归写法)
Implement an iterative stack
剑指 Offer 58 - II. 左旋转字符串
How many checks does kubedm series-01-preflight have
Web APIs DOM node
Annotation and reflection
卷积神经网络——卷积层
kubeadm系列-02-kubelet的配置和启动
EOJ 2021.10 E. XOR tree
剑指 Offer 05. 替换空格
Bit mask of bit operation
Pointnet++学习