1 Star 0 Fork 0

单身并不可笑嘛 / leetcode刷题记录

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
26. 删除排序数组中的重复项 675 Bytes
一键复制 编辑 原始数据 按行查看 历史
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
class Solution:
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) == 1:
return len(nums)
i = 0
while i<len(nums) -1:
if nums[i] == nums[i+1]:
nums.remove(nums[i])
else:
i += 1
return len(nums)
Python
1
https://gitee.com/caideyipi/leetcode_brush_title_record.git
git@gitee.com:caideyipi/leetcode_brush_title_record.git
caideyipi
leetcode_brush_title_record
leetcode刷题记录
master

搜索帮助