Time: 0 ms (100.00%), Space: 43.7 MB (7.03%) - LeetHub

This commit is contained in:
Deven
2023-05-28 18:58:16 -04:00
parent 96402faa0c
commit 6c85ce002d
@@ -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;
}
}