From 8f5e73f4d4d2d59e4b6f56b3832f97e28cf411d5 Mon Sep 17 00:00:00 2001 From: KEQI HUANG Date: Sun, 4 Feb 2018 22:37:35 -0600 Subject: [PATCH] Update 083._remove_duplicates_from_sorted_list.md --- 083._remove_duplicates_from_sorted_list.md | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/083._remove_duplicates_from_sorted_list.md b/083._remove_duplicates_from_sorted_list.md index bdca462..5f7c079 100644 --- a/083._remove_duplicates_from_sorted_list.md +++ b/083._remove_duplicates_from_sorted_list.md @@ -9,25 +9,20 @@ Easy +dummy 大法 - -``` +```python class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ - cur = head - while cur: - if cur.next: - if cur.val == cur.next.val: - cur.next = cur.next.next - else: - cur = cur.next - # cur.next None - else: - break - return head + dummy = head + while head: + while head.next and head.next.val == head.val: + head.next = head.next.next # skip duplicated node + head = head.next # not duplicate of current node, move to next node + return dummy -``` \ No newline at end of file +``` -- GitLab