mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
26 lines
651 B
Java
26 lines
651 B
Java
/**
|
|
* 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;
|
|
}
|
|
} |