Last active
March 16, 2016 02:13
-
-
Save cangoal/33be02147ae62ba72905 to your computer and use it in GitHub Desktop.
LeetCode - Remove Duplicates from Sorted List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| public ListNode deleteDuplicates(ListNode head) { | |
| if(head == null) return head; | |
| ListNode pre = head, cur = head.next; | |
| while(cur != null){ | |
| if(cur.val != pre.val){ | |
| cur = cur.next; | |
| pre = pre.next; | |
| } else { | |
| pre.next = cur.next; | |
| cur = pre.next; | |
| } | |
| } | |
| return head; | |
| } | |
| // | |
| public ListNode deleteDuplicates(ListNode head) { | |
| ListNode ret = head; | |
| if(head == null) | |
| return head; | |
| while(head.next != null){ | |
| ListNode p1 = head.next; | |
| if(p1.val == head.val){ | |
| head.next = p1.next; | |
| }else{ | |
| head = head.next; | |
| } | |
| } | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment