当前位置:网站首页>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 :
边栏推荐
- Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
- 常见的最优化方法
- CF1634 F. Fibonacci Additions
- Pointnet++ learning
- Fried chicken nuggets and fifa22
- 26、 File system API (device sharing between applications; directory and file API)
- Haut OJ 1321: mode problem of choice sister
- Maximum number of "balloons"
- EOJ 2021.10 E. XOR tree
- Wazuh开源主机安全解决方案的简介与使用体验
猜你喜欢
随机推荐
智慧工地“水电能耗在线监测系统”
常见的最优化方法
sync.Mutex源码解读
CF1637E Best Pair
【Jailhouse 文章】Look Mum, no VM Exits
Annotation and reflection
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
AtCoder Grand Contest 013 E - Placing Squares
SSH password free login settings and use scripts to SSH login and execute instructions
Using HashMap to realize simple cache
Reflection summary of Haut OJ freshmen on Wednesday
Drawing dynamic 3D circle with pure C language
2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
A misunderstanding about the console window
shared_ Repeated release heap object of PTR hidden danger
PC register
How many checks does kubedm series-01-preflight have
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
Haut OJ 2021 freshmen week II reflection summary









