Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 16, 2016 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/b31347aed2fe140384215156004790a5 to your computer and use it in GitHub Desktop.
Save jianminchen/b31347aed2fe140384215156004790a5 to your computer and use it in GitHub Desktop.
Remove duplicate in sorted linked list - facebook code lab - stack overflow issue - first practice
/**
* Definition for singly-linked list.
* class ListNode {
* public int val;
* public ListNode next;
* ListNode(int x) { val = x; next = null; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode a) {
if(a==null)
return null;
if(a.next == null)
return a;
if(a.val == a.next.val)
{
a.next = a.next.next;
return deleteDuplicates(a);
}
else
{
a.next = deleteDuplicates(a.next);
return a;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment