当前位置:网站首页>leetcode: 899. Ordered Queue [Thinking Question]
leetcode: 899. Ordered Queue [Thinking Question]
2022-08-03 15:33:00 【Looking Back at the White Speed Dragon King】
Analysis
k = 1 is nothing to say, go back and forth
If k > 1, we can hold down one at a time and connect its next one
This changes from 1 to 2 to 3, until all can be restored to any ordering we want
So when k is greater than 1 we can restore the smallest lexicographical order
ac code
class Solution:def orderlyQueue(self, s: str,k: int) -> str:# mathif k == 1:ans = sn = len(s)for i in range(n):s = s[1:] + s[0]ans = min(ans, s)return ans# k >= 2, do everythingreturn ''.join(sorted(s))
Summary
Is your head rusted today?
边栏推荐
猜你喜欢
How to prevent hacking Windows server security Settings
6000 字+,帮你搞懂互联网架构演变历程!
苹果开发「AI 建筑师」GAUDI:根据文本生成超逼真 3D 场景!
一次做数据报表的踩坑经历,让我领略了数据同步增量和全量的区别
深入浅出Flask PIN
方舟生存进化开服需要多少钱
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
CS免杀姿势
Essentially a database data recovery 】 【 database cannot read data recovery case
JS basics--judgment
随机推荐
DC-DC 2C (40W/30W) JD6606SX2 power back application
夜神浏览器fiddler抓包
2021年12月电子学会图形化二级编程题解析含答案:绘制多边形
6000 字+,帮你搞懂互联网架构演变历程!
问题10:注册页面的易用性测试?
2022-08-03日报:汪林望 vs 刘铁岩:AI、机器学习在材料科学研究中能发挥哪些作用?
ECCV 2022 | Relational Query-Based Temporal Action Detection Methods
【网络结构】VGG
身为程序员的我们如何卷死别人?破局重生。
随笔-Unity中一个简易的Spine动画控制器
Neural networks, cool?
跨桌面端之组件化实践
新版本的 MaxCompute 中,SQL支持的 LIMIT OFFSET 的语法是什么功能?
指令重排以及案例
ECCV 2022 | 基于关系查询的时序动作检测方法
MySQL性能优化的'4工具+10技巧'
深入浅出Flask PIN
证实了,百度没有快照了
How Navicat connects to MySQL on a remote server
随笔-UGUI中LayoutGroup来自适应长度图片长度