赞
踩
分类:列表
知识点:
从右往左遍历每一个字符 my_str[::-1]
题目来自【牛客】
- def reverse_unique(n):
- # 将输入的整数转换为字符串,这样可以从右向左遍历每一位
- str_n = str(n)
- # 创建一个空列表来保存不重复的数字
- unique_digits = []
- # 从右向左遍历每一位
- for digit in str_n[::-1]:
- # 如果数字已经在列表中,就跳过它
- if digit in unique_digits:
- continue
- # 否则,将数字添加到列表中
- unique_digits.append(digit)
- # 将列表中的数字连接起来,形成一个新的整数
- new_n = int(''.join(unique_digits))
- return new_n
-
- input_str = input().strip()
- print(reverse_unique(input_str))

by 软件工程小施同学
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。