We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6061cd3 commit 053209dCopy full SHA for 053209d
阿里在线编程算法题/最小字典序.py
@@ -24,12 +24,13 @@ def Solution(data):
24
"当位置1和位置2交换后 需要从2开始找最近一个比他小的A交换"
25
data[index], data[index + 1] = data[index + 1], data[index]
26
tem = index + 1 # 记录当前进行到哪一个字符 "B"
27
- while index < lenght:
28
- if data[index] == "A":
29
- data[tem + 1] = "B"
30
- data[index] = data[tem]
+ while tem < lenght:
+ if data[tem] == "A":
+ data[index + 1] = "A"
+ data[tem] = "B"
31
break
32
- index += 1
+ tem += 1
33
+ index += 1
34
35
36
@@ -47,6 +48,6 @@ def Solution(data):
47
48
return "".join(data)
49
50
-tem = "ABABAB"
51
+tem = "AABAB"
52
res = Solution(tem)
53
print(res)
0 commit comments