Added 26 solutions
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// Author: Rodney Shaghoulian
|
||||
// Github: github.com/rshaghoulian
|
||||
// HackerRank: hackerrank.com/rshaghoulian
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class Solution {
|
||||
public static void main(String[] args) {
|
||||
/* Create and fill Linked List of Integers */
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int N = scan.nextInt();
|
||||
LinkedList<Integer> list = new LinkedList<>();
|
||||
for (int i = 0; i < N; i++) {
|
||||
int value = scan.nextInt();
|
||||
list.add(value);
|
||||
}
|
||||
|
||||
/* Perfrom queries on Linked List */
|
||||
int Q = scan.nextInt();
|
||||
for (int i = 0; i < Q; i++) {
|
||||
String action = scan.next();
|
||||
if (action.equals("Insert")) {
|
||||
int index = scan.nextInt();
|
||||
int value = scan.nextInt();
|
||||
list.add(index, value);
|
||||
} else { // "Delete"
|
||||
int index = scan.nextInt();
|
||||
list.remove(index);
|
||||
}
|
||||
}
|
||||
scan.close();
|
||||
|
||||
/* Print our updated Linked List */
|
||||
for (Integer num : list) {
|
||||
System.out.print(num + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user