题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); while (num % 10 == 0) { num = sc.nextInt(); } String str = String.valueOf(num); char[] chs = str.toCharArray(); Set<Character> cset = new TreeSet<>(); List<Character> cl = new ArrayList<>(); for (int i = chs.length - 1; i >= 0; i--) { if (cset.add(chs[i])) { //不重复,true,就是里面还没有 cl.add(chs[i]); } } for (Character ch : cl) { System.out.print(ch); } } }