We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a83f577 commit 75227bfCopy full SHA for 75227bf
src/task_1089/Solution.java
@@ -0,0 +1,28 @@
1
+package task_1089;
2
+
3
+import java.util.Arrays;
4
5
+class Solution {
6
+ public void duplicateZeros(int[] arr) {
7
+ int[] tmp = Arrays.copyOf(arr, arr.length);
8
+ int tmpIndex = 0;
9
+ for (int i = 0; i < tmp.length; i++) {
10
+ if (tmp[i] != 0) {
11
+ if (tmpIndex <= arr.length - 1) {
12
+ arr[tmpIndex] = tmp[i];
13
+ tmpIndex++;
14
+ }
15
+ } else {
16
+ if (tmpIndex <= arr.length - 2) {
17
18
+ arr[tmpIndex+1] = tmp[i];
19
+ tmpIndex += 2;
20
+ } else if (tmpIndex <= arr.length - 1) {
21
22
23
24
25
26
27
28
+}
0 commit comments