题解 | #提取不重复的整数#

提取不重复的整数

https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int num = sc.nextInt();
            HashSet<Integer> hs = new HashSet<>();
            String result = "";
            
            while(num > 0) {
                int res = num % 10;
                num /= 10;
                if(hs.add(res)) {
                    result = result + res;
                }
            }
            
            System.out.print(result);
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务