题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), newN = 0; int[] occuredTimes = new int[10]; while (n > 0) { int remainder = n % 10; n /= 10; if (occuredTimes[remainder] > 0) { continue; } else { occuredTimes[remainder]++; newN *= 10; newN += remainder; } } System.out.println(newN); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); for (int i = str.length() - 1; i >= 0; i--) { if (str.lastIndexOf(str.charAt(i)) == i) { System.out.print(str.charAt(i)); } } } }
#华为笔试#