面試哈希映射關於代碼戰鬥的問題,需要幫助優化我的蠻力解決方案。這裏是問題: 給定一個字符串str和對的數組,指示字符串中的哪些索引可以交換,返回允許的交換所產生的字典順序最大的字符串。您可以交換指數任意次數。 例 For str = "abdc" and pairs = [[1, 4], [3, 4]], the output should be
swapLexOrder(str, pairs)
給定字符串W,我想實現其下一個字符串的字典順序更大。 eg 1:
givenstring = "hegf"
nexthighest = "hefg"
我曾嘗試到現在就在這裏, from itertools import permutations
q = int(input())
for i in range(q):
s = input()
if s == s[::-