From 27176fdff070c9481f928c16198b773e50474914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Wed, 21 Jun 2023 22:47:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=AE=97=E6=B3=95=E9=A2=98=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../problem_solving_02.py" | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git "a/14_\345\210\267\351\242\230/problem_solving_02.py" "b/14_\345\210\267\351\242\230/problem_solving_02.py" index 3fec830..e912ab0 100644 --- "a/14_\345\210\267\351\242\230/problem_solving_02.py" +++ "b/14_\345\210\267\351\242\230/problem_solving_02.py" @@ -46,13 +46,14 @@ from typing import List class Solution: def removeDuplicates(self, nums: List[int]) -> int: - """ - 列表去重后列表的长度 - :param nums: - :return: - """ - result = set(nums) - return len(result) + if not nums: + return 0 + k = 1 + for i in range(1, len(nums)): + if nums[i] != nums[i - 1]: + nums[k] = nums[i] + k += 1 + return k if __name__ == '__main__': -- GitLab