当前位置:网站首页>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
- DOM对象能干什么?
- 玉溪卷烟厂通过正确选择时序数据库 轻松应对超万亿行数据
- 干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
- 浪潮—英伟达打造元宇宙新方案,虚拟人的故事将再破你的认知
- 苏州大学:从PostgreSQL到TDengine
- 聊天app开发——防炸麦以及节省成本的内容鉴定方法
- Machine Learning (Chapter 1) - Feature Engineering
- Question G: Word Analysis ← Questions for the second provincial competition of the 11th Blue Bridge Cup Competition
猜你喜欢

For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received

深度学习经典网络 -- Inception系列(稀疏结构)

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!...

机器学习概述

完全背包问题

Web Server 设置缓存响应字段的一些推荐方案

Simple implementation of a high-performance clone of Redis using .NET (1)
![[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly](/img/19/a3f58d5a1150d99571205a7e2f7345.png)
[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly

MySQL数据库实战(1)

用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
随机推荐
synchronized
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?...
ABAB-740新语法
MATLAB programming and application 2.7 Structural data and unit data
面试一面
【无标题】函数,对象,方法的区别
在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
Apache Doris系列之:数据模型
再谈“雷克萨斯”安全装置失效!安全手册疑点重重,网友:细思极恐
【TypeScript】Why choose TypeScript?
Basic using MySQL database
用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
CADEditorX ActiveX 14.1.X
MySQL database combat (1)
Simple implementation of a high-performance clone of Redis using .NET (1)
ERC20通证标准是什么?
Advanced use of MySQL database
Cookie和Session使用
numpy
完全背包问题