提取不重复的数字

提取不重复的整数

http://www.nowcoder.com/questionTerminal/253986e66d114d378ae8de2e6c4577c1

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String s = sc.nextLine();
            HashSet<Character> set = new HashSet<>();
            ArrayList<Character> list = new ArrayList<>();
            for(int i = s.length() - 1; i >= 0; --i){
                if(!set.contains(s.charAt(i))){
                    set.add(s.charAt(i));
                    list.add(s.charAt(i));
                }
            }
            for(int i = 0; i < list.size(); ++i){
                System.out.print(list.get(i));
            }
                System.out.println();
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 11:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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