题目:
https://leetcode-cn.com/problems/design-linked-list/
import java.util.ArrayList; public class _707_MyLinkedList { private ArrayList<Integer> list; public _707_MyLinkedList() { list = new ArrayList<>(); } public int get(int index) { if (index >= 0 && index < list.size()) { return list.get(index); } else { return -1; } } public void addAtHead(int val) { list.add(0,val); } public void addAtTail(int val) { list.add(val); } public void addAtIndex(int index, int val) { list.add(index,val); } public void deleteAtIndex(int index) { if (index >= 0 && index < list.size()) { list.remove(index); } } }