Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 053209d

Browse files
committed
未完成
1 parent 6061cd3 commit 053209d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

阿里在线编程算法题/最小字典序.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ def Solution(data):
2424
"当位置1和位置2交换后 需要从2开始找最近一个比他小的A交换"
2525
data[index], data[index + 1] = data[index + 1], data[index]
2626
tem = index + 1 # 记录当前进行到哪一个字符 "B"
27-
while index < lenght:
28-
if data[index] == "A":
29-
data[tem + 1] = "B"
30-
data[index] = data[tem]
27+
while tem < lenght:
28+
if data[tem] == "A":
29+
data[index + 1] = "A"
30+
data[tem] = "B"
3131
break
32-
index += 1
32+
tem += 1
33+
index += 1
3334

3435

3536

@@ -47,6 +48,6 @@ def Solution(data):
4748
return "".join(data)
4849

4950

50-
tem = "ABABAB"
51+
tem = "AABAB"
5152
res = Solution(tem)
5253
print(res)

0 commit comments

Comments
 (0)