24. Same Tree
EasyDesign a dynamic array class. The data structure should expose indexed reads/writes, support appending/removing from the end, and report its current capacity.
dynamic arrayResizable ArrayArrayListvector
Your DynamicArray class should support the following operations:
DynamicArray(int capacity): Initialize an empty array with the provided capacity.int get(int i): Return the element at index i. Assume 0 <= i < length.void set(int i, int n): Set the element at index i to n.void pushback(int n): Add element n to the end of the array.int popback(): Remove and return the element at the end of the array.int getCapacity(): Return the current capacity of the array.
If pushback() is called when the array is full, double the capacity before inserting the new element.
Example 1:
Input: ["push", 1, "getCap", "push", 2] Output: [null, null, 1, null]
Constraints:
1 <= capacity <= 10000 <= n <= 1000