算法题先排序再使用快慢指针法,慢指针用来替换统计和替换重复的元素,话不或说,上代码: def helper(nums:list)->list: if len(nums) <2: return nums.sort() slow = 0 temp = None for i in range(1, len(nums)): if nums[i] == nums[i-1]: if nums[i] != temp: slow += 1 temp = nums[i] nums[slow-1] = nums[i] return nums[:slow]