[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;
    }
}
posted @ 2018-07-30 16:58  ACBingo  阅读(106)  评论(0编辑  收藏  举报