题解 | 提取不重复的整数
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
String n = in.nextLine().trim();
Stack<Character> stack = new Stack<>();
Set<Character> set = new LinkedHashSet<>();
for (int i = 0; i < n.length(); i++) {
stack.push(n.charAt(i));
}
while(!stack.isEmpty()){
//System.out.print(stack.pop());
set.add(stack.pop());
}
for(Character c:set){
System.out.print(c);
}
}
in.close();
}
}
查看6道真题和解析