1.题目描述
Given a sorted linked list, delete all duplicates such that each element appear only once.
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
Example 1:
Input: 1->1->2
Output: 1->2
Example 2:
Input: 1->1->2->3->3
Output: 1->2->3
2.Solutions
类似于82题解决思路:
1 | public static ListNode deleteDuplicates(ListNode head) { |
单指针:
1 | public static ListNode deleteDuplicates(ListNode head) { |
递归:
1 | public ListNode deleteDuplicates(ListNode head) { |