题解 | 提取不重复的整数

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        HashSet<Integer> set=new HashSet<>();
        while(n!=0){
            int a=n%10;
            if(set.add(a))
                System.out.print(a);
            n/=10;
        }
        
    }
}
  1. 如果add能添加成功,就说明是第一个出现的元素
  2. 如果add添加不成功,说明是重复元素
全部评论

相关推荐

点赞 评论 收藏
分享
AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务