Leetcode in C-Move Zeroes 2021.1.1

Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
  1. You must do this in-place without making a copy of the array.
  2. Minimize the total number of operations.
void moveZeroes(int* nums, int numsSize){
int j = 0;
for(int i=0;i<numsSize;i++){

if(nums[i]!=0){
nums[j]=nums[i];
j++;
}
}
printf(“%d”,j);
for(int k=j;k<numsSize;k++){
nums[k]=0;
}


return 0;
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to create custom plugin in Mautic

IT Asset Lifecycle Management: 5 Steps And How To Improve Them With AssetSonar

IT Asset Lifecycle Management: 5 Steps And How To Improve Them With AssetSonar

WAX Technical How To #14

Download FunEasyLearn MOD APK v2.9.4 (Premium Unlock) For Android — Free — Latest Version

Working the Oscar Magic: A Story of Extreme Growth, A Mighty Team, and Oscar’s Building Blocks

Co-workers collaborating

Mobile web automation testing with Appium

MyListing v1.6 Update!

Using F#’s Paket with .NET Core

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
學習筆記

學習筆記

More from Medium

Part 2: Q+A with GraphAudio’s MEMS Engineer, Kim Reid

LeetCode 278 First Bad Version

Leetcode Problem 1342: Number of steps to reduce a number to zero

CS373 Spring 2022: Shreya Sridhar