实现支持下列接口的「快照数组」- SnapshotArray:
SnapshotArray(int length)
void set(index, val)
index
val
int snap()
snap_id
snap()
1
int get(index, snap_id)
示例:
输入:["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]] 输出:[null,null,0,null,5] 解释: SnapshotArray snapshotArr = new SnapshotArray(3); // 初始化一个长度为 3 的快照数组 snapshotArr.set(0,5); // 令 array[0] = 5 snapshotArr.snap(); // 获取快照,返回 snap_id = 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // 获取 snap_id = 0 的快照中 array[0] 的值,返回 5
提示:
1 <= length <= 50000
50000
set
snap
get
0 <= index < length
0 <= snap_id <
0 <= val <= 10^9