Created
June 26, 2022 23:39
-
-
Save RakhmedovRS/beb76bad4c696c6ca962a46e5631d545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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