mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-15 09:57:09 +00:00
Time: 0 ms (100.00%), Space: 43.7 MB (7.03%) - LeetHub
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Definition for singly-linked list.
|
||||
* public class ListNode {
|
||||
* int val;
|
||||
* ListNode next;
|
||||
* ListNode() {}
|
||||
* ListNode(int val) { this.val = val; }
|
||||
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
|
||||
* }
|
||||
*/
|
||||
class Solution {
|
||||
public ListNode deleteDuplicates(ListNode head) {
|
||||
ListNode current = head;
|
||||
while (current != null) {
|
||||
ListNode next = current.next;
|
||||
|
||||
while (next != null && current.val == next.val) {
|
||||
next = next.next;
|
||||
}
|
||||
|
||||
current.next = next;
|
||||
current = next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user