Created
July 16, 2016 04:02
-
-
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
This file contains 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 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