class Solution { public: void moveZeroes(vector<int>& nums) { int j=0; for(int i=0;i<nums.size();i++) { if(nums[i]!=0) { nums[j]=nums[i]; j++; } } for(int i=j+1;j<nums.size();j++) { nums[j]=0; } } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter