Created
September 1, 2015 18:11
-
-
Save cxtadment/701c8f1a156948657d2f to your computer and use it in GitHub Desktop.
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
| /** | |
| * Definition for ListNode | |
| * public class ListNode { | |
| * int val; | |
| * ListNode next; | |
| * ListNode(int x) { | |
| * val = x; | |
| * next = null; | |
| * } | |
| * } | |
| */ | |
| public class Solution { | |
| /** | |
| * @param ListNode head is the head of the linked list | |
| * @return: ListNode head of the linked list | |
| */ | |
| public static ListNode deleteDuplicates(ListNode head) { | |
| // write your code here | |
| if (head == null) { | |
| return null; | |
| } | |
| ListNode dummyHead = new ListNode(0); | |
| dummyHead.next = head; | |
| head = dummyHead; | |
| while (head.next != null && head.next.next != null) { | |
| if (head.next.val == head.next.next.val) { | |
| int val = head.next.val; | |
| while (head.next != null && head.next.val == val) { | |
| head.next = head.next.next; | |
| } | |
| } else { | |
| head = head.next; | |
| } | |
| } | |
| return dummyHead.next; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment