1.简述:
给出已排序的链表头head,删除所有重复元素,使每个元素只出现一次。返回 已排序的链表。
示例 1:
输入:head = [1,1,2]
输出:[1,2]
示例 2:
输入:head = [1,1,2,3]
输出:[1,2,3]
2.实现代码:class Solution { public ListNode deleteDuplicates(ListNode head) { if (head == null) { return head; } ListNode cur = head; while (cur.next != null) { if (cur.val == cur.next.val) { cur.next = cur.next.next; } else { cur = cur.next; } } return head; }}