1. 程式人生 > >83. Remove Duplicates from Sorted List

83. Remove Duplicates from Sorted List

ret cat element del each return color app 排好序

Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

含義:從已經排好序的列表中,刪除重復值節點

 1     public ListNode deleteDuplicates(ListNode head) {
 2         ListNode curNode=head;
3 while (curNode != null && curNode.next != null) 4 { 5 if (curNode.val == curNode.next.val) 6 { 7 curNode.next = curNode.next.next; 8 }else 9 { 10 curNode = curNode.next; 11 } 12
} 13 return head; 14 }

83. Remove Duplicates from Sorted List