题解 | #提取不重复的整数#

提取不重复的整数

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());
        }
    }
}

哈希表,采用有序的链表结构即可

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-23 14:13
这是聊岔撇了吗,相同的话问了两遍
吴offer选手:上下文切换这一块
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-25 17:23
做完了怎么知道过没过呀
投递京东等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务