forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1146.js
More file actions
37 lines (34 loc) · 690 Bytes
/
1146.js
File metadata and controls
37 lines (34 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @param {number} length
*/
var SnapshotArray = function(length) {
this.dif = {};
this.snaps = [];
};
/**
* @param {number} index
* @param {number} val
* @return {void}
*/
SnapshotArray.prototype.set = function(index, val) {
this.dif[index] = val;
};
/**
* @return {number}
*/
SnapshotArray.prototype.snap = function() {
let {...newDif} = this.dif;
this.snaps.push(newDif);
return this.snaps.length - 1;
};
/**
* @param {number} index
* @param {number} snap_id
* @return {number}
*/
SnapshotArray.prototype.get = function(index, snap_id) {
if (this.snaps[snap_id][index]) {
return this.snaps[snap_id][index];
}
return 0;
};