Lintcode112 Remove Duplicates From Sorted List solution 题解
来源:互联网 发布:网络系统建设方案 编辑:程序博客网 时间:2024/06/05 07:14
【题目描述】
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.
给定一个排序链表,删除所有重复的元素每个元素只留下一个。
【题目链接】
www.lintcode.com/en/problem/remove-duplicates-from-sorted-list/
【题目解析】
根据题目要求,我们需要删除链表中的一些元素。对于只包含next属性的链表,在删除操作时,我们需要用到该元素now的前一个元素prev。其删除过程为:
prev -> next = now -> next
这样就可以直接将该元素从链表中删除,这里需要注意的是头指针的删除。
那么哪些元素需要删除呢?根据题目描述我们可以得到两种情况:
1该元素与后一个元素重复
now -> val == now -> next -> val
2该元素表示的数字已经删除过一次
now -> val == needDelete
总的来说本题并不难,只需要注意一点点细节就可以通过。
【参考答案】
www.jiuzhang.com/solutions/remove-duplicates-from-sorted-list/
阅读全文
0 0
- Lintcode112 Remove Duplicates From Sorted List solution 题解
- Lintcode113 Remove Duplicates From Sorted List || solution 题解
- LeetCode题解:Remove Duplicates from Sorted List
- LeetCode题解:Remove Duplicates from Sorted List
- Lintcode100 Remove Duplicates From Sorted Array solution 题解
- Lintcode101 Remove Duplicates From Sorted Array || solution 题解
- [LeetCode] Remove Duplicates from Sorted List II, Solution
- LeetCode题解:Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List ---Leetcode 我的java题解
- LeetCode83之Remove Duplicates from Sorted List的Java题解
- LeetCode 题解(160): Remove Duplicates from Sorted List II
- LeetCode 题解(225) : Remove Duplicates from Sorted List
- LeetCode题解-83-Remove Duplicates from Sorted List
- Leetcode题解 83. Remove Duplicates from Sorted List
- LeetCode题解-82-Remove Duplicates from Sorted List II
- leetcode题解-83. Remove Duplicates from Sorted List
- leetcode题解-83. Remove Duplicates from Sorted List
- leetcode题解-82. Remove Duplicates from Sorted List II
- 树莓派 Raspberry Pi 更换国内源(支持不同发行版本)
- XML、JSON及其解析
- hibernate(2)
- 动态规划总结(二)
- Codeforces Round #431 (Div. 2) A. Odds and Ends
- Lintcode112 Remove Duplicates From Sorted List solution 题解
- printf内幕----编程内幕(1)
- springboot学习二(springboot相关配置)
- Bigtable: A Distributed Storage System for Structured Data : part6 Refinements
- java 重复请求过滤(并发访问)
- 假如时光倒流,我会这么学习Java
- Oracle 块头的事务槽
- 实数向整数的强制转换
- 位运算