[leetcode] 83. 删除排序链表中的重复元素

83. 删除排序链表中的重复元素

链表操作

class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return head;
        if (head.next == null) return head;
        ListNode now = head.next;
        ListNode last = head;
        while (now != null) {
            while (now != null && now.val == last.val) {
                now = now.next;
            }
            last.next = now;
            last = now;
            if (now != null)
                now = now.next;
        }
        return head;
    }
}
原文地址:https://www.cnblogs.com/acbingo/p/9391494.html