Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 17, 2014 11:57
Show Gist options
  • Save Cee/75ab2d00971b99c22900 to your computer and use it in GitHub Desktop.
Save Cee/75ab2d00971b99c22900 to your computer and use it in GitHub Desktop.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode p = head;
while (p != null){
if (p.next != null){
if (p.next.val == p.val){
p.next = p.next.next;
} else {
p = p.next;
}
} else {
p = p.next;
}
}
return head;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment