记得之前做过这个概念,但是没想到第二次看到这个概念,还是G了,难受阿,就不能给点用例过吗。-----考完思考了一下一些坑在哪以一个极端一点的为例子:777771234误区1:很容易搞成789xxxx,然后说不定程序还会报错。误区2:只需要最开始重复的数字比之前的大就行,其他的保持小数字。比如改成78xxxxxx后,你第三位数字应该是一个较小的数字了所以应该是780xxxxxx。误区3:注意可能小的数字也不是一定能用的,比如这里很明显你改成780xxxxx后,后面的数字应该是5了,不能是1,也就是7805xxxx。也就是说一开始就应该把不能用的数字明确好。不知道有没有逻辑错误的地方或者没考虑到的,有的话可以讨论一下。---更新--误区4:还得进位,比如988,就得是1023了写了代码,如果有问题也欢迎指出:def need_carry(x:str):# 碰到重复的数字,且该数字的所有高位都已经用完used = [False] * 10num_list = list(x)for num in num_list:used[int(num)] = Truenum_dict = {}for i in range(len(num_list)):num = num_list[i]if num in num_dict:if all(used[j] for j in range(int(num)+1,10)):return Trueelse:num_dict[num] = Truereturn Falsedef process(x):used = [False] * 10if need_carry(x):x = '1'+'0'*len(x)num_list = list(x)for num in num_list:used[int(num)] = Trueunused = [str(i) for i, flag in enumerate(used) if not flag]num_dict = {}change_made = Falsefor i in range(len(num_list)):num = num_list[i]if num in num_dict:if change_made: # 已经改过一次了,所以直接用unused里的最小的num_list[i] = unused.pop(0)else:for j in range(int(num) + 1, 10):if str(j) in unused:unused.remove(str(j))num_list[i] = str(j)change_made = Truebreakelse:num_dict[num] = Truereturn ''.join(num_list)