当前位置:网站首页>LeetCode:899. 有序队列【思维题】
LeetCode:899. 有序队列【思维题】
2022-08-04 01:43:00 【星空皓月】
题目描述

思路
当k = 1时,轮转字符串,得到一个字典树最小的字符串;
当k = 2时,可以想象成一个环,将s[0]单拿出来,让字符串转动,可以放到任意位置,s[1],s[2]…都是如此,这样就能使得将整个字符串的每一位调整到任意位置。所以将该字符串排为升序即可。
AC代码
class Solution:
def orderlyQueue(self, s: str, k: int) -> str:
if k == 1:
ans = s
for i in range(len(s) - 1):
s = s[1:] + s[0]
ans = min(ans, s)
return ans
return ''.join(sorted(s)) # 注sorted返回的时list,要将其转化为str
边栏推荐
- 天地图坐标系转高德坐标系 WGS84转GCJ02
- C 学生管理系统_分析
- redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
- 【QT小记】QT中信号和槽的基本使用
- 静态/动态代理模式
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- 2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
- 实例039:有序列表插入元素
- Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
- 工程制图复习题(带答案)
猜你喜欢

数组_滑动窗口 | leecode刷题笔记

什么是SVN(Subversion)?

持续投入商品研发,叮咚买菜赢在了供应链投入上

敏捷交付的工程效能治理

Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg

Use of lombok annotation @RequiredArgsConstructor

idea中diagram使用

IDEA02:配置SQL Server2019数据库

Parquet encoding

Example 037: Sorting
随机推荐
贴纸拼词 —— 记忆化搜索 / 状压DP
5.scrapy中间件&分布式爬虫
C语言力扣第54题之螺旋矩阵。模拟旋转
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
GNSS[0]- Topic
贪吃蛇游戏Bug解析及功能扩展
priority_queue元素为指针时,重载运算符失效
可变字符串
C程序编译和预定义详解
Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
实例038:矩阵对角线之和
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
Promise 解决阻塞式同步,将异步变为同步
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
持续投入商品研发,叮咚买菜赢在了供应链投入上
静态文件快速建站
GNSS【0】- 专题
HBuilderX的下载安装和创建/运行项目
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
How to copy baby from Taobao (or Tmall store) through API interface to Pinduoduo interface code docking tutorial