给定一个排序链表,删除全部重复的元素使得每一个元素只留下一个。code
案例:排序
给定 1->1->2
,返回 1->2
List
给定 1->1->2->3->3
,返回 1->2->3
链表
public ListNode deleteDuplicates(ListNode head){ if (head==null||head.next==null){ return head; } ListNode pre = head; ListNode next = head.next; while (next!=null){ if (pre.val==next.val){ pre.next=next.next; } else { pre = next; } next=next.next; } return head; }