Python 3 不知对不对😂 s = 'aaabcdbcdefzzz' def lis(s): dp = [1] * len(s) dic = {} for index, char in enumerate(s): dic[index] = char for i in range(len(s)): for j in range(i): if ord(s[i]) >= ord(s[j]): if dp[j] + 1 > dp[i]: dp[i] = dp[j]+ 1 dic[i] = dic[j] + s[i] index = dp.index(max(dp)) return dic[index] print(lis(s))