-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSolution.java
More file actions
42 lines (33 loc) · 1.09 KB
/
Copy pathSolution.java
File metadata and controls
42 lines (33 loc) · 1.09 KB
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.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < N; i++) {
list.add(scanner.nextInt());
}
int Q = scanner.nextInt();
for (int i = 0; i < Q; i++) {
String queryType = scanner.next();
if (queryType.equals("Insert")) {
int x = scanner.nextInt();
int y = scanner.nextInt();
list.add(x, y);
}
if (queryType.equals("Delete")) {
int x = scanner.nextInt();
if (x >= 0 && x < list.size()) {
list.remove(x);
}
}
}
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i));
if (i < list.size() - 1) {
System.out.print(" ");
}
}
scanner.close();
}
}