Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RakhmedovRS/beb76bad4c696c6ca962a46e5631d545 to your computer and use it in GitHub Desktop.
Save RakhmedovRS/beb76bad4c696c6ca962a46e5631d545 to your computer and use it in GitHub Desktop.
class MyLinkedList {
ArrayList<Integer> list;
public MyLinkedList() {
list = new ArrayList<>();
}
public int get(int index) {
if (index >= list.size()) return -1;
return list.get(index);
}
public void addAtHead(int val) {
list.add(0, val);
}
public void addAtTail(int val) {
list.add(list.size(), val);
}
public void addAtIndex(int index, int val) {
if (index > list.size()) return;
list.add(index, val);
}
public void deleteAtIndex(int index) {
if (index >= list.size()) return;
list.remove(index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment