双指针:Left和Right,将左指针的零与右指针的非零数交换,且非零数的相对顺序并未改变。
1 def movezeros(nums): 2 n = len(nums) 3 left = right =0 4 while right<n: 5 if nums[right] != 0: 6 nums[left],nums[right]=nums[right],nums[left] 7 # print(nums) 8 left+=1 9 right+=1 10 # return nums
标签:right,nums,零数,283,移动,指针 From: https://www.cnblogs.com/wanxueyu/p/16771003.html