Skip to content

Instantly share code, notes, and snippets.

@cxtadment
Created September 1, 2015 18:11
Show Gist options
  • Select an option

  • Save cxtadment/701c8f1a156948657d2f to your computer and use it in GitHub Desktop.

Select an option

Save cxtadment/701c8f1a156948657d2f to your computer and use it in GitHub Desktop.
/**
* 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