Skip to content

Commit 6cb46f5

Browse files
committed
Runtime: 43 ms (Top 90.65%) | Memory: 81.4 MB (Top 44.17%)
1 parent 5ad9c0f commit 6cb46f5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Runtime: 43 ms (Top 90.65%) | Memory: 81.4 MB (Top 44.17%)
12
class SnapshotArray {
23

34
TreeMap<Integer,Integer>[] snapshotArray;
45
int currSnapId;
5-
6+
67
public SnapshotArray(int length) {
78
snapshotArray = new TreeMap[length];
89
for(int i=0;i<length;i++)
@@ -11,18 +12,18 @@ public SnapshotArray(int length) {
1112
}
1213
currSnapId =0;
1314
}
14-
15+
1516
public void set(int index, int val) {
1617
snapshotArray[index].put(currSnapId,val);
1718
}
18-
19+
1920
public int snap() {
2021
return currSnapId++;
2122
}
22-
23+
2324
public int get(int index, int snap_id) {
2425
Integer lowerKey = snapshotArray[index].floorKey(snap_id);
25-
26+
2627
if(lowerKey !=null)
2728
{
2829
return snapshotArray[index].get(lowerKey);
@@ -31,12 +32,10 @@ public int get(int index, int snap_id) {
3132
}
3233
}
3334

34-
35-
3635
/**
3736
* Your SnapshotArray object will be instantiated and called as such:
3837
* SnapshotArray obj = new SnapshotArray(length);
3938
* obj.set(index,val);
4039
* int param_2 = obj.snap();
4140
* int param_3 = obj.get(index,snap_id);
42-
*/
41+
*/

0 commit comments

Comments
 (0)