We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
List<Integer> l = new ArrayList<>();
for (int i = 0; i < n; i++) {
int x = scan.nextInt();
l.add(x);
}
int m = scan.nextInt();
scan.nextLine();
for (int i = 0; i < m; i++) {
String s = scan.nextLine();
if (s.equals("Insert")) {
int a = scan.nextInt();
int b = scan.nextInt();
l.add(a, b);
if (scan.hasNextLine()) {
scan.nextLine();
}
} else if (s.equals("Delete")) {
int x = scan.nextInt();
l.remove(x);
if (scan.hasNextLine()) {
scan.nextLine();
}
}
}
for (Integer element : l) {
System.out.print(element + " ");
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java List
You are viewing a single comment's thread. Return to all comments →
my code: import java.io.; import java.util.;
public class Solution {
}