Remove Duplicates from Sorted List II 题解
Last updated
Was this helpful?
Last updated
Was this helpful?
题目来源:
> Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2->3, return 2->3.
解题思路:
用一个变量标记是否有相同的节点,直到不同的才连接到result中。
别忘了最后的节点->next需要置空。