-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayOperations.java
More file actions
31 lines (31 loc) · 851 Bytes
/
ArrayOperations.java
File metadata and controls
31 lines (31 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Leetcode - 2460
import java.util.*;
public class ArrayOperations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < nums.length; i++) {
nums[i] = sc.nextInt();
}
for (int i = 0; i < nums.length-1; i++) {
if (nums[i] == nums[i+1]) {
nums[i] = nums[i]*2;
nums[i+1] = 0;
}
}
int count = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != 0)
nums[count++] = nums[i];
}
while (count<nums.length) {
nums[count++] = 0;
}
for (int i : nums) {
System.out.print(i+" ");
}
System.gc();
sc.close();
}
}