899. 有序队列
为保证权益,题目请参考 899. 有序队列(From LeetCode).
解决方案1
Python
python
# 899. 有序队列
# https://leetcode.cn/problems/orderly-queue/
import copy
class Solution:
def orderlyQueue(self, s: str, k: int) -> str:
def orderk1(s: str) -> str:
ans = copy.copy(s)
s = list(s)
for i in range(len(s)):
t = "".join(s)
s = s[1:] + s[0:1]
if t < ans:
ans = t
return ans
def orderk2(s: str) -> str:
s = list(s)
s = sorted(s)
ans = "".join(s)
return ans
ans = None
if k == 1:
ans = orderk1(s)
else:
ans = orderk2(s)
return ans
if __name__ == "__main__":
so = Solution()
print(so.orderlyQueue("cba", 1))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36