题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<Integer, Integer> map = new LinkedHashMap<>(); while (sc.hasNext()) { String a = sc.nextLine(); for (int i = a.length(); i > 0; i--) { String b = a.substring(i - 1, i); if (!map.containsKey(Integer.parseInt(b))) { map.put(Integer.parseInt(b), Integer.parseInt(b)); } } StringBuilder sb = new StringBuilder(); map.forEach((key, value) -> sb.append(value)); System.out.println(sb.toString()); } } }
哈希表,采用有序的链表结构即可