Advertisement
Shahd_Elmeniawy

https://leetcode.com/problems/move-zeroes/submissions/

Oct 9th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void moveZeroes(vector<int>& nums) {
  4.         int n=nums.size(), k=0;
  5.         for(auto it=nums.begin();it!=nums.end();++it){
  6.             if(*it==0){
  7.                k++;
  8.                 nums.erase(it);
  9.                 it--;
  10.             }
  11.         }
  12.     for(int i=0;i<k;i++){
  13.         nums.push_back(0);
  14.     }
  15.          for(auto & It : nums){
  16.              cout<<It<<",";
  17.          }
  18.        
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement