/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode? next;
* ListNode([this.val = 0, this.next]);
* }
*/
class Solution {
ListNode? deleteDuplicates(ListNode? head) {
if (head==null) {
return head;
}
var th = head;
while (th.next!=null) {
if (th.val == th.next?.val) {
th.next = th.next?.next;
continue;
}
if (th.next != null) {
th = th.next!;
} else {
th.next = null;
}
}
return head;
}
}
those ? ! takes my too much time