题目:27. 移除元素
易错点:
- 差点猛住了,可以用pass顺着逻辑来识别
代码示例:
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
slow = 0
for fast in range(len(nums)):
if nums[fast] == val: # 删除
pass
else: # 不等于就赋值
nums[slow] = nums[fast]
slow+=1
return slow
扩展写法:
总结:
参考:
https://ahym1n4sq5.feishu.cn/docx/Q38XdytUAoUv6Oxf6Zscb2Bzn0e
标签:slow,nums,int,day06,fast,27,移除 From: https://www.cnblogs.com/liqi175/p/17963842