We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
首先,谢谢提供如此好的一个教程帮助初学者或像我这种忘记的差不多的人重新学习。 示例代码似乎有误,我在leecode中尝试了,不能通过,因为nums中的元素被替换,所以好比[1,1,1,2,2,3]这样的list会出错。 我找到一个稍微简单的办法处理这种问题,直接删除list中重复的元素,示例代码如下(n=2,使用其他n>2的情况): class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) <= 2: return len(nums) idx = 2 while idx < len(nums): if nums[idx-2]== nums[idx]: del nums[idx] else: idx+=1 return len(nums)
The text was updated successfully, but these errors were encountered:
cpp version根本没有occur这个变量
Sorry, something went wrong.
No branches or pull requests
首先,谢谢提供如此好的一个教程帮助初学者或像我这种忘记的差不多的人重新学习。
示例代码似乎有误,我在leecode中尝试了,不能通过,因为nums中的元素被替换,所以好比[1,1,1,2,2,3]这样的list会出错。
我找到一个稍微简单的办法处理这种问题,直接删除list中重复的元素,示例代码如下(n=2,使用其他n>2的情况):
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) <= 2:
return len(nums)
idx = 2
while idx < len(nums):
if nums[idx-2]== nums[idx]:
del nums[idx]
else:
idx+=1
return len(nums)
The text was updated successfully, but these errors were encountered: