标签:sort and sorted array ref element move def for
class Solution(object):
# 重复项保留一个
def removeDuplicates(self, nums):
n = len(nums)
if n<2: return n
i, j = 0, 1
while i<=j and j<n:
if nums[i] == nums[j]:
j += 1
else:
nums[i+1] = nums[j]
i += 1
j += 1
return i+1
class Solution(object):
def removeElement(self, nums, val):
ind = 0
for i in range(len(nums)):
if nums[i] != val:
nums[ind] = nums[i]
ind += 1
return ind
标签:sort and sorted array ref element move def for
原文地址:https://www.cnblogs.com/yutingting/p/12744060.html