Given a number in array form, move all the 0's to the end of the array.
[1,3,9,0,5,4,0,0,6,6,0,2,4,1,0,4,9,7,0,0,1,2,0]
Given a number in array form, move all the 0's to the end of the array.
[1,3,9,0,5,4,0,0,6,6,0,2,4,1,0,4,9,7,0,0,1,2,0]
Permalink: http://problemotd.com/problem/move-zeroes/
Content curated by @MaxBurstein
Comments:
yanik - 9 years, 4 months ago
Remove from array and pop in at the end...
reply permalink
Anonymous - 9 years, 3 months ago
reply permalink
Daniel - 9 years, 2 months ago
You can do it in-place in O(n+k) where k is the length of the largest consecutive run of zeros.
reply permalink
Daniel - 9 years, 2 months ago
Sorry I meant to say O(n*k) not O(n+k)
reply permalink