当前位置:网站首页>使用递归字符串反转和全排列
使用递归字符串反转和全排列
2022-07-23 01:26:00 【程程呀是小白】
目录
本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金 只有这一个。如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白。
上一篇文章链接为:thymeleaf在网页中上传文件_程程呀是小白的博客-CSDN博客 ,本篇是使用idea软件Java语言写两个题。
如果是springboot的话请看springboot创建项目_程程呀是小白的博客-CSDN博客 ,这个是从头开始的还没有学完springboot,一起学习呀!!!!
1.用递归实现字符串倒转

代码块如下:
public static void main(String[] args) {
System.out.println(reverse("程程呀!!!"));
}
public static String reverse(String originStr) {
if(originStr == null | originStr.length()== 1) {
return originStr;
}
return reverse(originStr.substring(1))+ originStr.charAt(0);
}
结果如图:
2.全排列:给6个数字的所有排列

代码块如下:
public static void main(String[] args) {
int[] x = {5,8,9,6,7,2};
perm(x);}
public static void perm(int[] list) {
perm(list,0);
}
private static void perm(int[] list, int k) {
if (k == list.length) {
for (int i = 0; i < list.length; i++) {
System.out.print(list[i]);
}
System.out.println();
}else{
for (int i = k; i < list.length; i++) {
swap(list, k, i);
perm(list, k + 1);
swap(list, k, i);
}
}
}private static void swap(int[] list, int k, int i) {
int temp = list[k];
list[k] = list[i];
list[i] = temp;
}
结果如图(放不下,可以自己试一下):

本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金 只有这一个。如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白。
上一篇文章链接为:thymeleaf在网页中上传文件_程程呀是小白的博客-CSDN博客 ,本篇是使用idea软件Java语言写两个题。
如果是springboot的话请看springboot创建项目_程程呀是小白的博客-CSDN博客 ,这个是从头开始的还没有学完springboot,一起学习呀!!!!
边栏推荐
- RNA 25. SCI文章中只有生信没有实验该怎么办?
- 券商真的有保本型理财产品吗?
- Emmet 语法简结
- input 输入完成时的触发事件
- Airserver third party projection software v7.3.0 Chinese Version (airplay terminal utility)
- Advantages of implementing automatic network performance monitoring
- 【无标题】
- IDM downloader free high-quality win download tool without restrictions
- 2022.7.22-----leetcode.757
- 【HLS】流水线仿真之排队函数的调用
猜你喜欢
随机推荐
1058 A+B in Hogwarts
解析创客教育活动所需的空间实践场
PyTorch可视化
动态设置小程序的navigationBarTitleText
解读随着教育改革的深入steam教育
BGP机房的优点
What is the combined effect of compose and recyclerview?
向后量子密码学迁移!美国NIST公布12家合作伙伴
[ManageEngine] six essential functions of network configuration management
[Huawei online battle service] how can new players make up frames when the client quits reconnection or enters the game halfway?
软件测试面试思路技巧和方法分享,学到就是赚到
rust allow dead_code
Summary of some open source libraries that drive MCU hardware debugger (including stlink debugger)
SPSS Chi-Square
Advantages of implementing automatic network performance monitoring
TFW6524完美替代进口PT6524芯片方案简介
Vscode连接服务器,密码正确,但是一直连接不上的解决办法
PHP gets the certificate number. There is no serialnumberhex, but only the serialnumber processing method
727. 最小窗口子序列 滑动窗口
【ManageEngine】网络配置管理的6大必备功能









