当前位置:网站首页>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 :
边栏推荐
- Implement an iterative stack
- Sword finger offer 04 Search in two-dimensional array
- Brief introduction to tcp/ip protocol stack
- Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
- kubeadm系列-02-kubelet的配置和启动
- Implement a fixed capacity stack
- Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
- Control Unit 控制部件
- 【Jailhouse 文章】Jailhouse Hypervisor
- CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
猜你喜欢
CF1634E Fair Share
剑指 Offer 53 - I. 在排序数组中查找数字 I
Implement an iterative stack
YOLOv5-Shufflenetv2
Sword finger offer 35 Replication of complex linked list
Brief introduction to tcp/ip protocol stack
Graduation project of game mall
On-off and on-off of quality system construction
Sword finger offer 09 Implementing queues with two stacks
Solution to game 10 of the personal field
随机推荐
搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
Common optimization methods
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
[jailhouse article] jailhouse hypervisor
Alu logic operation unit
Introduction to tools in TF-A
注解与反射
Kubedm series-00-overview
个人开发的渗透测试工具Satania v1.2更新
Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
sync. Interpretation of mutex source code
Introduction to memory layout of FVP and Juno platforms
Haut OJ 1245: large factorial of CDs --- high precision factorial
object serialization
Haut OJ 1401: praise energy
过拟合与正则化
利用HashMap实现简单缓存
读者写者模型
Developing desktop applications with electron
Configuration and startup of kubedm series-02-kubelet