当前位置:网站首页>2022.8.3-----leetcode.899
2022.8.3-----leetcode.899
2022-08-04 01:59:00 【路Lu727】
public String orderlyQueue(String s, int k) {
//k为1,只能在s的字符环中选择一个开头使其最小
if (k == 1) {
String smallest = s;
String ss =s+s;
int n = s.length();
for (int i = 1; i < n; i++) {
if(ss.substring(i,i+n).compareTo(smallest)<0)
smallest=ss.substring(i,i+n);
}
return smallest;
} else {
//k>1,可以交换任意相邻两字符的顺序,最后可以实现所有字符的排序
char[] arr = s.toCharArray();
Arrays.sort(arr);
return new String(arr);
}
}边栏推荐
- 一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
- Presto中broadcast join和partition join执行计划的处理过程
- IDEA02:配置SQL Server2019数据库
- Parquet encoding
- nodejs+express实现数据库mysql的访问,并展示数据到页面上
- Day13 Postman的使用
- 2022G1工业锅炉司炉考试练习题及模拟考试
- Engineering drawing review questions (with answers)
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- 一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包
猜你喜欢
随机推荐
实例037:排序
What is SVN (Subversion)?
The browser
FeatureNotFound( bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
云开发旅游打卡广场微信小程序源码(含视频教程)
FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
简单的线性表的顺序表示实现,以及线性表的链式表示和实现、带头节点的单向链表,C语言简单实现一些基本功能
Variable string
企业虚拟偶像产生了实质性的价值效益
Apache DolphinScheduler actual combat task scheduling platform - a new generation of distributed workflow
Web APIs BOM- 操作浏览器:swiper 插件
GNSS[0]- Topic
Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
ssh服务详解
第13章 网络安全漏洞防护技术原理与应用
(cf)Codeforces Round #811 (Div. 3)A--E详细题解
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
LDO investigation
关联接口测试
通用的测试用例编写大全(登录测试/web测试等)









