题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.Scanner; /** * <a href="https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1">提取不重复的数</a> * * @author hll[yellowdradra@foxmail.com] * @since 2024-06-13 */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String num = sc.nextLine(); System.out.println(solution(num)); } public static String solution(String num) { boolean[] repeat = new boolean[10]; StringBuilder sb = new StringBuilder(); for (int i = num.toCharArray().length - 1; i >= 0; i--) { int index = num.charAt(i) - '0'; if (!repeat[index]) { sb.append(num.charAt(i)); repeat[index] = true; } } return sb.toString(); } }