题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
String str = scanner.nextLine();
//利用LinkedHashSet无序且唯一的特性
HashSet<Integer> hashSet = new LinkedHashSet<>();
//利用字符串从右边往左依次向hashSet中添加
for(int i = str.length()-1; i>=0; i--){
hashSet.add(Integer.parseInt(
new String(new char[]{str.charAt(i)})
));
}
//迭代器打印
Iterator iterator = hashSet.iterator();
while(iterator.hasNext()){
System.out.print(iterator.next());
}
}
}
}