题解 | Java#提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.io.InputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num=scanner.nextInt();
char [] chars=Integer.toString(num).toCharArray();
String str="";
for (int i=chars.length-1;i>=0;i--){
if (!str.contains(chars[i]+"")){
str += chars[i];
}
System.out.println(Integer.valueOf(str)/10);
return;
}
System.out.println(Integer.valueOf(str));
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num=scanner.nextInt();
char [] chars=Integer.toString(num).toCharArray();
String str="";
for (int i=chars.length-1;i>=0;i--){
if (!str.contains(chars[i]+"")){
str += chars[i];
}
}
//避免位数为0
if (Integer.valueOf(str)%10==0){System.out.println(Integer.valueOf(str)/10);
return;
}
System.out.println(Integer.valueOf(str));
}
}