Created
March 15, 2023 14:28
-
-
Save VallarasuS/932ec11897b3adc94b6e8f534f24f3e6 to your computer and use it in GitHub Desktop.
1089. Duplicate Zeros - https://leetcode.com/problems/duplicate-zeros/description/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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