File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -1061,6 +1061,7 @@ _If you like this project, please leave me a star._ ★
10611061| 1179| [ Reformat Department Table] ( https://leetcode.com/problems/reformat-department-table/ ) | [ Solution] ( ../master/database/_1179.sql ) | | Easy |
10621062| 1173| [ Immediate Food Delivery I] ( https://leetcode.com/problems/immediate-food-delivery-i/ ) | [ Solution] ( ../master/database/_1173.sql ) | | Easy |
10631063| 1148| [ Article Views I] ( https://leetcode.com/problems/article-views-i/ ) | [ Solution] ( ../master/database/_1148.sql ) | | Easy |
1064+ | 1146| [ Snapshot Array] ( https://leetcode.com/problems/snapshot-array/ ) | [ Javascript] ( ./javascript/_1146.js ) | | Easy |
10641065| 1141| [ User Activity for the Past 30 Days I] ( https://leetcode.com/problems/user-activity-for-the-past-30-days-i/ ) | [ Solution] ( ../master/database/_1141.sql ) | | Easy |
10651066| 1084| [ Sales Analysis III] ( https://leetcode.com/problems/sales-analysis-iii/ ) | [ Solution] ( ../master/database/_1084.sql ) | | Easy |
10661067| 1083| [ Sales Analysis II] ( https://leetcode.com/problems/sales-analysis-ii/ ) | [ Solution] ( ../master/database/_1083.sql ) | | Easy |
Original file line number Diff line number Diff line change 1+ /**
2+ * Author: Phuong Lam
3+ */
4+
5+ /**
6+ * @param {number } length
7+ */
8+ var SnapshotArray = function ( length ) {
9+ this . changes = { }
10+ this . snapShots = [ ]
11+ }
12+
13+ /**
14+ * @param {number } index
15+ * @param {number } val
16+ * @return {void }
17+ */
18+ SnapshotArray . prototype . set = function ( index , val ) {
19+ this . changes [ index ] = val
20+ }
21+
22+ /**
23+ * @return {number }
24+ */
25+ SnapshotArray . prototype . snap = function ( ) {
26+ this . snapShots . push ( this . changes )
27+ this . changes = { }
28+ return this . snapShots . length - 1
29+ }
30+
31+ /**
32+ * @param {number } index
33+ * @param {number } snap_id
34+ * @return {number }
35+ */
36+ SnapshotArray . prototype . get = function ( index , snap_id ) {
37+ while ( snap_id >= 0 && this . snapShots [ snap_id ] [ index ] === undefined ) snap_id --
38+ if ( snap_id >= 0 ) return this . snapShots [ snap_id ] [ index ]
39+ return 0
40+ }
41+
42+ /**
43+ * Your SnapshotArray object will be instantiated and called as such:
44+ * var obj = new SnapshotArray(length)
45+ * obj.set(index,val)
46+ * var param_2 = obj.snap()
47+ * var param_3 = obj.get(index,snap_id)
48+ */
You can’t perform that action at this time.
0 commit comments