C++ stable_partition() pretty much does exactly this

  • 0

    The std::partition() function will move the zeros, but it might change relative order of the other elements. std::stable_partition() retains relative order.

        class Solution {
            void moveZeroes(vector<int>& nums) {
                    begin(nums), end(nums),
                    [](int val) { return val != 0; });

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.