当前位置:网站首页>leetcode:899. 有序队列【思维题】
leetcode:899. 有序队列【思维题】
2022-08-03 15:19:00 【白速龙王的回眸】
分析
k = 1没什么好说,倒着走一圈
如果k > 1,我们可以每次按住一个,把它的下一个接起来
这样从1个变2个变3个,直到全部都能够还原成我们想要的任何排序
因此k大于1时候我们可以还原字典序的最小
ac code
class Solution:
def orderlyQueue(self, s: str, k: int) -> str:
# math
if k == 1:
ans = s
n = len(s)
for i in range(n):
s = s[1:] + s[0]
ans = min(ans, s)
return ans
# k >= 2, do everything
return ''.join(sorted(s))
总结
今天你的脑袋生锈了吗?
边栏推荐
- devops-2:Jenkins的使用及Pipeline语法讲解
- The general trend, another key industry related to Sino-US competition, has reached a critical moment
- 您的移动端app安全吗
- JS每晚24:00更新某方法
- PHP中高级面试题 – 第三天
- 高性能创作本,日常修图剪辑选华硕无畏Pro15 2022完全足矣!
- PAT乙级-B1010 一元多项式求导(25)
- 基于matlab的遥测信道的基本特性仿真分析
- Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
- 生物统计师与临床医生协同研究使用的低代码洞察平台丨数据科学 x 临床医学
猜你喜欢
问题5:发现缺陷怎么办?缺陷的类型有哪些?
Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil
Ark server open tool, server tutorial win
Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
2021年12月电子学会图形化一级编程题解析含答案:下雨
Detailed explanation of cloud hard disk EVS and how to use and avoid pits [HUAWEI CLOUD is simple and far]
问题6:下拉框测试点
cmd 关闭端口
简介undo log、truncate、以及undo log如何帮你回滚事物?
R7 6800H+RTX3050+120Hz 2.8K OLED screen, Intrepid Pro15 2022 pre-sale
随机推荐
R7 6800H+RTX3050+120Hz 2.8K OLED屏,无畏Pro15 2022开启预售
liunx服务器遇到SYN_SENT洪水攻击
HDU Largest prime factor(埃拉托色尼筛选法求素数模板法改动)
新版本MaxCompute 的SQL支持 UDF 分区裁剪的逻辑是怎样的?
How much does Ark Survival Evolved cost?
liunx服务器nohup不输出日志文件的方法
问题5:发现缺陷怎么办?缺陷的类型有哪些?
After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution
跨桌面端之组件化实践
With a single operation, I improved the SQL execution efficiency by 10,000,000 times!
南京一研究所回应招聘硕士保安:负责安全生产等,48人选1
【重构map】【重构filter】【重构Some】【重构reduce方法】【重构flat函数】
你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
eolink告诉你,国内Api行业,可以内卷到什么程度?
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
问题9:为什么有边界值的测试?
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
雷克萨斯lm的安全性如何,通过两个角度来聊这个话题
2021年12月电子学会图形化四级编程题解析含答案:聪明的小猫
Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil