当前位置:网站首页>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);
}
}
边栏推荐
- Parquet encoding
- 什么是SVN(Subversion)?
- 织梦响应式酒店民宿住宿类网站织梦模板(自适应手机端)
- Array_Sliding window | leecode brushing notes
- Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
- 大佬们,读取mysql300万单表要很长时间,有什么参数可以优惠,或者有什么办法可以快点
- What is SVN (Subversion)?
- Day13 Postman的使用
- Web APIs BOM - operating browser: swiper plug-in
- Simple sorting (summer vacation daily question 14)
猜你喜欢
随机推荐
Hey, I had another fight with HR in the small group!
【QT小记】QT中信号和槽的基本使用
22/8/3(板子)树状dp板子+中国剩余定理+求组合数3,4+容斥原理
html select tag assignment database query result
C程序编译和预定义详解
织梦响应式酒店民宿住宿类网站织梦模板(自适应手机端)
Promise solves blocking synchronization and turns asynchronous into synchronous
C# 构造函数业务场景测试项目
Slipper - virtual point, shortest path
实例039:有序列表插入元素
Parquet encoding
html select标签赋值数据库查询结果
关联接口测试
esp32发布机器人电池电压到ros2(micro-ros+CoCube)
Intranet penetration - application
LDO investigation
持续投入商品研发,叮咚买菜赢在了供应链投入上
initramfs详解----添加硬盘驱动并访问磁盘
Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.