• 48.7%

https://leetcode.com/problems/move-zeroes/#/description

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note:

1. You must do this in-place without making a copy of the array.
2. Minimize the total number of operations.

Oct 17， 2017

https://discuss.leetcode.com/topic/32632/my-simple-c-solution

My simple C++ solution

Oct 21， 2017

https://discuss.leetcode.com/topic/24745/c-accepted-code

C++ Accepted Code

https://discuss.leetcode.com/topic/25077/one-line-c-code-20ms

One line c++ code, 20ms

The idea comes from the c++ erase/remove idiom.

https://discuss.leetcode.com/topic/25163/c-1-line-or-3-lines-clean-code

C++ 1 line (or 3 lines) clean code

https://discuss.leetcode.com/topic/28941/very-simple-python-solutions

Very simple python solutions

Solution 1: traverse and swap last 0 and last non 0

Solution 2 : one-liner from @toontong: use sort() with customized compare function