当前位置:网站首页>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
边栏推荐
- Observability:你所需要知道的关于 Syslog 的一些知识
- 特征值与特征向量
- VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience
- Array_Sliding window | leecode brushing notes
- 工程制图复习题(带答案)
- 静态/动态代理模式
- SAP SD模块前台操作
- Multithreading JUC Learning Chapter 1 Steps to Create Multithreading
- 谁说程序员不懂浪漫,表白代码来啦~
- Example 040: Reverse List
猜你喜欢
Web APIs BOM- 操作浏览器:swiper 插件
敏捷交付的工程效能治理
C程序编译和预定义详解
企业虚拟偶像产生了实质性的价值效益
OpenCV如何实现Sobel边缘检测
nodejs切换版本使用(不需要卸载重装)
priority_queue元素为指针时,重载运算符失效
Example: 036 is a prime number
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
如何用C语言代码实现商品管理系统开发
随机推荐
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
工程制图复习题
ASP.NET 获取数据库的数据并写入到excel表格中
DDTL:远距离的域迁移学习
Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
Use of lombok annotation @RequiredArgsConstructor
网页三维虚拟展厅为接入元宇宙平台做基础
VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience
LDO investigation
Web APIs BOM- 操作浏览器:swiper 插件
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
Slipper - virtual point, shortest path
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
【QT小记】QT中信号和槽的基本使用
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
html select标签赋值数据库查询结果
IDEA02:配置SQL Server2019数据库
观察者模式
静态/动态代理模式