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.
Hmm I think my code is clean, but idk is optimized or not!
import java.io.;
import java.util.;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
for(int i = 0; i < number;++i){
int getNum = sc.nextInt();
arr.add(getNum);
}
int getQueries = sc.nextInt();
for(int i = 0; i < getQueries;++i){
sc.nextLine(); // getInt has \n
String getInput = sc.nextLine();
if(getInput.equals("Insert")){
int index = sc.nextInt();
int newNumber = sc.nextInt();
arr.add(index, newNumber);
}else if(getInput.equals("Delete")){
int checkNum = sc.nextInt();
arr.remove(checkNum);
}
}
for(int check : arr){
System.out.print(check + " ");
}
}
}
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 →
Hmm I think my code is clean, but idk is optimized or not! import java.io.; import java.util.;
public class Solution {
}