4 Lines in C++ using STL


  • 1
    void moveZeroes(vector<int>& nums)
    {
    	int zero_num = count_if(nums.begin(), nums.end(), [](int i){return i == 0; });
    	auto it = remove_if(nums.begin(), nums.end(), [](int i){return i == 0; });
    	nums.erase(it, nums.end());
    	while (zero_num--) nums.push_back(0);
    }

Log in to reply
 

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