Created
July 5, 2019 11:56
-
-
Save Desolve/55fea85d03d195ae3ff6a2d7e5500524 to your computer and use it in GitHub Desktop.
0083 Remove Duplicates from Sorted List
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. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { val = x; } | |
* } | |
*/ | |
class Solution { | |
public ListNode deleteDuplicates(ListNode head) { | |
ListNode ite = head; | |
while(ite != null) { | |
ListNode tmp = ite.next; | |
while (tmp != null && ite.val == tmp.val) tmp = tmp.next; | |
ite.next = tmp; | |
ite = tmp; | |
} | |
return head; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment