You are viewing a single comment's thread. Return to all comments →
public class Solution {
private List<Integer> theList; private Scanner sc; public Solution(Scanner sc) { this.theList = new ArrayList<>(); this.sc = sc; int sizeList = sc.nextInt(); init(sizeList, sc); } private void init(int sizeList, Scanner sc) { if (sizeList > 0) { theList.add(sc.nextInt()); init(sizeList - 1, sc); } } public void choose(String action){ int index = sc.nextInt(); if(action.equalsIgnoreCase("insert")){ int element = sc.nextInt(); theList.add(index, element); } else theList.remove(index); } public List<Integer> getList() { for (int element : theList) { System.out.print(element + " "); } return theList; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); Solution solution = new Solution(sc); int queries = sc.nextInt(); for(int i = 0; i < queries; i++){ sc.nextLine(); String action = sc.nextLine(); solution.choose(action); } solution.getList(); }
}
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 →
public class Solution {
}