题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
通解: 哈希
特解: 但因为这道题目的数字只有0~9 只有10个 所以可以搞一个数组当做哈希用来判断。 比如 0为没有 1为有。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//定义一个哈希数组长度为10 ------ 0 到9
int[] hash = new int[10];
//遍历
int num = sc.nextInt();
while (num != 0) {
//余数
int x = num % 10;
if (hash[x] == 0) {
System.out.print(x);
hash[x] = 1;
}
num = num / 10;
}
}
}

