-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava List.java
42 lines (41 loc) · 1.27 KB
/
Java List.java
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
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
// Java 8
public class Solution {
public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
final int size = in.nextInt();
final List<Integer> list = new LinkedList<>();
for (int i = 0; i < size; i++) {
list.add(in.nextInt());
}
final int commandCount = in.nextInt();
for (int i = 0; i < commandCount; i++) {
in.nextLine();
String command = in.nextLine();
// System.out.println("command: " + command);
if (command.equals("Insert")) {
int index = in.nextInt();
// System.out.println("index: " + index);
int value = in.nextInt();
// System.out.println("value: " + value);
list.add(index, value);
} else {
int index = in.nextInt();
list.remove(index);
}
}
int count = 0;
for (Integer number : list) {
System.out.print(number);
if (count != list.size() - 1) {
System.out.print(" ");
}
count++;
}
}
}
// Have a quick day.