题目:
方法:
class Solution:
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
j = 0
for i in range(1,len(nums)):
if nums[j] == 0 and nums[i] != 0:
nums[i] , nums[j] = nums[j] , nums[i]
elif nums[j] == 0 and nums[i] == 0:
continue
j += 1
双指针问题
同时维护两个指针i,j
i指向当前list需要调换的0的位置
j指向当前遍历list的位置
移动j的同时比较i与j指向的元素