首页
Python
Java
前端
数据库
Linux
Chatgpt专题
开发者工具箱
orderly专题
leetcode 899. Orderly Queue
原题链接 You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string. Return the lexicographically smallest string you could have aft
阅读更多...
【Leetcode】899. Orderly Queue 899. 有序队列
解法 数学解法 首先,假如能够证明序列里任意相邻字母都可以交换,那肯定可以直接排出最小值 当K>1时,我们想交换S[i]和S[i+1],那么操作出S[i:]+S[:i],然后,由于K至少为2,所以这时候可以先把S[i+1]放到后面去,变成S[i]+S[i+2:]+S[:i]+S[i+1],然后再放S[i],得到S[i+2:]+S[:i]+S[i+1]+S[i],最后再依次把S[i+2:]这
阅读更多...