0
给定字符串W,我想实现其下一个字符串的字典顺序更大。查找字符串的下一个最高字母序列排列
eg 1:
givenstring = "hegf"
nexthighest = "hefg"
我曾尝试到现在就在这里,
from itertools import permutations
q = int(input())
for i in range(q):
s = input()
if s == s[::-1]:
print("no answer")
else:
x = ["".join(p) for p in list(permutations(s))]
x.sort()
index = x.index(s)
print(x[index+1])
,因为这不是解决这个的有效途径。 u能请建议我更好的办法来解决这个问题
更多解释见本网站 - https://www.nayuki.io/page/next-lexicographical-permutation-algorithm –
谢谢你帮我 –