题目:485. 最大连续 1 的个数
易错点:
- 第一眼想到从队尾开始交换,后来发现不行。
代码示例:
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
slow = 0
for fast in range(len(nums)):
if nums[fast] != 0: # 只要不等于0 就交换
nums[slow],nums[fast] = nums[fast],nums[slow]
slow +=1
扩展写法:
总结:
- QQSS 轻轻松松
参考:
标签:slow,nums,个数,day06,fast,485 From: https://www.cnblogs.com/liqi175/p/17963523