HTMLify

Leetcode - Remove Duplicates from Sorted List - Dart
Views: 27 | Author: abh
/**
 * 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;
    }
}

Comments

abh 2025-04-03 16:17

My first dart solution on leetcode hehe

those ? ! takes my too much time