当前位置:网站首页>LeetCode 899 有序队列[字典序] HERODING的LeetCode之路
LeetCode 899 有序队列[字典序] HERODING的LeetCode之路
2022-08-03 10:59:00 【HERODING23】
解题思路:
其实只要想明白,就是非常简单的题目,当k等于1时,那么字符串s可以想象成循环字符串,所能构成的字符串就是以任意节点为首,按序一直到尾构成,找到最小的字典序即可,k>1,那么相当于所有字符的全排列,直接sort即可,代码如下:
class Solution {
public:
string orderlyQueue(string s, int k) {
if(k == 1) {
int n = s.size();
string minS = s;
s += s;
for(int i = 1; i < n; i ++) {
string temp = s.substr(i, n);
minS = min(minS, temp);
}
return minS;
}
sort(s.begin(), s.end());
return s;
}
};
边栏推荐
- 本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
- [Star Project] Little Hat Plane Battle (9)
- BPMN和DMN基本概念和使用案例
- Win10/11 删除文件资源管理器左侧栏目文件夹
- For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
- gbase在轨道交通一般都采用哪种高可用架构?
- ABAB-740新语法
- 混合型界面:对话式UI的未来
- 出色的移动端用户验证
- 试题G:单词分析 ← 第十一届蓝桥杯大赛第二场省赛赛题
猜你喜欢
Machine Learning (Chapter 1) - Feature Engineering
Matplotlib
type="module" you know, but type="importmap" you know
Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)
2022年五面蚂蚁、三面拼多多、字节跳动最终拿offer入职拼多多
【二分查找详解外加递归写法】附有全部代码
用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
Matplotlib
「全球数字经济大会」登陆 N 世界,融云提供通信云服务支持
机器学习概述
随机推荐
[Bubble sort and odd-even sorting]
MATLAB程序设计与应用 2.6 字符串
[Detailed explanation of binary search plus recursive writing method] with all the code
MySQL database combat (1)
多态详细讲解(简单实现买票系统模拟,覆盖/重定义,多态原理,虚表)
Machine Learning (Chapter 1) - Feature Engineering
机器学习(第一章)—— 特征工程
袋鼠云思枢:数驹 DTengine,助力企业构建高效的流批一体数据湖计算平台
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
go——并发编程
redis基础知识总结——数据类型(字符串,列表,集合,哈希,集合)
【JDBC以及内部类的讲解】
For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
How to use outside the PHP command in the container
在 Chrome 开发者工具里通过 network 选项模拟网站的离线访问模式
QT with OpenGL(HDR)
开源一夏 | 教你快速实现“基于Docker快速构建基于Prometheus的MySQL监控系统”
OS层面包重组失败过高,数据库层面gc lost 频繁
【二分查找详解外加递归写法】附有全部代码
如何通过DBeaver 连接 TDengine?