当前位置:网站首页>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;
}
};
边栏推荐
- 历史拉链数据处理有人做过吗
- 卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
- numpy
- 机器学习(第一章)—— 特征工程
- redis基础知识总结——数据类型(字符串,列表,集合,哈希,集合)
- build --repot
- Spinner文字显示不全解决办法
- Web Server 设置缓存响应字段的一些推荐方案
- Babbitt | Metaverse daily must-read: Players leave, platforms are shut down, and the digital collection market is gradually cooling down. Where is the future of the industry?...
- 谷歌实用插件分享
猜你喜欢

Spinner文字显示不全解决办法

卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结

Dva.js 新手入门指南

CADEditorX ActiveX 14.1.X

Analysis of the idea of the complete knapsack problem

孙宇晨式“溢价逻辑”:不局限眼前,为全人类的“星辰大海”大胆下注

云原生 Dev0ps 实践

Programmers architecture practice way: software architecture basic concepts and thinking

在 Chrome 开发者工具里通过 network 选项模拟网站的离线访问模式

Classical Architecture and Memory Classification of Embedded Software Components
随机推荐
ABAB-740新语法
Spinner文字显示不全解决办法
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
[Bubble sort and odd-even sorting]
ARIMA实现(亲测可用)
混动产品谁更吃香,看技术还是看市场?
实至名归!九章云极DataCanvas公司荣获智能制造领域多项殊荣
Web Server 设置缓存响应字段的一些推荐方案
3分钟实现内网穿透(基于ngrok实现)
用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
像用户体验设计师一样思考
LP流动性挖矿DAPP系统开发丨流动性挖矿功能原理及说明
Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)
出色的移动端用户验证
MySQL数据库高级使用
How to use outside the PHP command in the container
【TypeScript】为什么要选择 TypeScript?
STM32入门开发 介绍SPI总线、读写W25Q64(FLASH)(硬件+模拟时序)
如何通过DBeaver 连接 TDengine?
优炫数据库在linux平台下服务启动失败的原因