Skip to content

Instantly share code, notes, and snippets.

@the-fejw
Created January 28, 2015 00:55
Show Gist options
  • Save the-fejw/24c98e5adc17579d896a to your computer and use it in GitHub Desktop.
Save the-fejw/24c98e5adc17579d896a 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) {
if (head == null)
return null;
ListNode itr1 = head;
ListNode itr2 = head.next;
while (itr2 != null) {
if (itr1.val == itr2.val) {
itr1.next = itr2.next;
} else {
itr1 = itr1.next;
}
itr2 = itr2.next;
}
return head;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment