当前位置:网站首页>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 58 - ii Rotate string left
- Solution to game 10 of the personal field
- 全排列的代码 (递归写法)
- Fried chicken nuggets and fifa22
- 剑指 Offer 04. 二维数组中的查找
- PC register
- Daily question - longest substring without repeated characters
- 每日一题-无重复字符的最长子串
- 利用HashMap实现简单缓存
- lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
猜你喜欢
随机推荐
Use of room database
SSH password free login settings and use scripts to SSH login and execute instructions
How many checks does kubedm series-01-preflight have
Haut OJ 1241: League activities of class XXX
Control Unit 控制部件
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
Codeforces Round #715 (Div. 2) D. Binary Literature
Convolution neural network -- convolution layer
Sword finger offer 09 Implementing queues with two stacks
Haut OJ 1218: maximum continuous sub segment sum
Solution to game 10 of the personal field
Reflection summary of Haut OJ freshmen on Wednesday
Acwing 4301. Truncated sequence
Using HashMap to realize simple cache
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
卷积神经网络简介
剑指 Offer 53 - II. 0~n-1中缺失的数字
A new micro ORM open source framework
第六章 数据流建模—课后习题
网络工程师考核的一些常见的问题:WLAN、BGP、交换机









