当前位置:网站首页>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;
}
};
边栏推荐
- 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!...
- Win10/11 删除文件资源管理器左侧栏目文件夹
- 如何改变sys_guid() 返回值类型
- SAP 电商云 Spartacus UI 的 External Routes 设计明细
- 如何将Oracle/MySQL中的数据迁移到GBase 8c中?
- Boolean 与numeric 无法互转
- 全新的Uber App设计
- Cookie和Session使用
- Classical Architecture and Memory Classification of Embedded Software Components
- 面试一面
猜你喜欢

二叉搜索树(搜索二叉树)模拟实现(有递归版本)

多态详细讲解(简单实现买票系统模拟,覆盖/重定义,多态原理,虚表)

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

Machine Learning Overview

servlet生命周期详解--【结合源码】

玉溪卷烟厂通过正确选择时序数据库 轻松应对超万亿行数据

Basic using MySQL database

开源一夏 | 教你快速实现“基于Docker快速构建基于Prometheus的MySQL监控系统”

程序员架构修炼之道:软件架构基本概念和思维

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!...
随机推荐
"Global Digital Economy Conference" landed in N World, Rongyun provides communication cloud service support
二叉搜索树(搜索二叉树)模拟实现(有递归版本)
C#/VB.NET 从PDF中提取表格
请问应该用什么关键字将内容主题设置为 dark 呢
全新的Uber App设计
关于OPENSSL的问题
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
numpy
ERC20通证标准是什么?
Boolean 与numeric 无法互转
面试官:工作两年了,这么简单的算法题你都不会?
MySQL数据库实战(1)
Binary search tree (search binary tree) simulation implementation (there is a recursive version)
Machines need tokens more than people
Traceback (most recent call last): File
通过GBase 8c Platform安装数据库集群时报错
Spinner文字显示不全解决办法
优炫数据库在linux平台下服务启动失败的原因
苏州大学:从PostgreSQL到TDengine
LyScript 实现对内存堆栈扫描