From 4a504699f2955e2a8f90e1d92b5c0aebac9833c3 Mon Sep 17 00:00:00 2001 From: eric496 Date: Sun, 21 Jun 2020 22:43:35 -0400 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=89=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E5=8E=BB=E9=87=8DPython3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...15\345\244\215\345\205\203\347\264\240.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git "a/\351\253\230\351\242\221\351\235\242\350\257\225\347\263\273\345\210\227/\345\246\202\344\275\225\345\216\273\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.md" "b/\351\253\230\351\242\221\351\235\242\350\257\225\347\263\273\345\210\227/\345\246\202\344\275\225\345\216\273\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.md" index 678236f..3e1cd14 100644 --- "a/\351\253\230\351\242\221\351\235\242\350\257\225\347\263\273\345\210\227/\345\246\202\344\275\225\345\216\273\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.md" +++ "b/\351\253\230\351\242\221\351\235\242\350\257\225\347\263\273\345\210\227/\345\246\202\344\275\225\345\216\273\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.md" @@ -66,6 +66,48 @@ ListNode deleteDuplicates(ListNode head) { ![labuladong](../pictures/labuladong.png) +[eric wang](https://www.github.com/eric496) 提供有序数组 Python3 代码 + +```python +def removeDuplicates(self, nums: List[int]) -> int: + n = len(nums) + + if n == 0: + return 0 + + slow, fast = 0, 1 + + while fast < n: + if nums[fast] != nums[slow]: + slow += 1 + nums[slow] = nums[fast] + + fast += 1 + + return slow + 1 +``` + +[eric wang](https://www.github.com/eric496) 提供有序链表 Python3 代码 + +```python +def deleteDuplicates(self, head: ListNode) -> ListNode: + if not head: + return head + + slow, fast = head, head.next + + while fast: + if fast.val != slow.val: + slow.next = fast + slow = slow.next + + fast = fast.next + + # 断开与后面重复元素的连接 + slow.next = None + return head +``` + [上一篇:如何高效解决接雨水问题](../高频面试系列/接雨水.md) [下一篇:如何寻找最长回文子串](../高频面试系列/最长回文子串.md) -- GitLab