[
two pointers
array
]
BinarySearch 0678 In-Place Move Zeros to End of List
Problem statement
https://binarysearch.com/problems/In-Place-Move-Zeros-to-End-of-List/
Solution
Equal to Leetcode 0283 Move Zeros.
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, nums):
beg, end = 0, 0
while end < len(nums):
if nums[end] != 0:
nums[beg], nums[end] = nums[end], nums[beg]
beg += 1
end += 1
return nums