Skip to content

Instantly share code, notes, and snippets.

@VallarasuS
Created March 15, 2023 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VallarasuS/932ec11897b3adc94b6e8f534f24f3e6 to your computer and use it in GitHub Desktop.
Save VallarasuS/932ec11897b3adc94b6e8f534f24f3e6 to your computer and use it in GitHub Desktop.
class Solution {
public void duplicateZeros(int[] arr) {
for(int i = 0; i < arr.length; i++) {
if(arr[i] == 0) {
shiftRight(arr, i);
i += 1;
}
}
}
public void shiftRight(int[] arr, int start) {
for(int right = arr.length - 1; right > start; right--) {
arr[right] = arr[right - 1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment