当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
Analysis of the idea of the complete knapsack problem
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
鸿蒙第三次
Who is more popular for hybrid products, depending on technology or market?
Matplotlib
Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
Classical Architecture and Memory Classification of Embedded Software Components
MySQL database combat (1)
随机推荐
智能合约是什么?
出色的移动端用户验证
Summary of redis basics - data types (strings, lists, sets, hashes, sets)
浪潮—英伟达打造元宇宙新方案,虚拟人的故事将再破你的认知
干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
SAP 电商云 Spartacus UI 的 External Routes 设计明细
[Bubble sort and odd-even sorting]
DOM对象能干什么?
CADEditorX ActiveX 14.1.X
机器比人更需要通证
混动产品谁更吃香,看技术还是看市场?
Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
白帽黑客与留守儿童破壁对“画”!ISC、中国光华科技基金会、光明网携手启动数字安全元宇宙公益展
What is a smart contract?
袋鼠云思枢:数驹 DTengine,助力企业构建高效的流批一体数据湖计算平台
C#+WPF 单元测试项目类高级程序员必知必会
创建C UDR时,指定的HANDLESNULLS的作用是什么?
Matplotlib
机器学习概述
build --repot