Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add solution for problem 1146#128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 2 commits intofishercoder1534:masterfromltp88:js-prolem-1146-solution
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1061,6 +1061,7 @@ _If you like this project, please leave me a star._ ★
|1179|[Reformat Department Table](https://leetcode.com/problems/reformat-department-table/)|[Solution](../master/database/_1179.sql) | | Easy |
|1173|[Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i/)|[Solution](../master/database/_1173.sql) | | Easy |
|1148|[Article Views I](https://leetcode.com/problems/article-views-i/)|[Solution](../master/database/_1148.sql) | | Easy |
|1146|[Snapshot Array](https://leetcode.com/problems/snapshot-array/)|[Javascript](./javascript/_1146.js)| | Easy |
|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 |
|1084|[Sales Analysis III](https://leetcode.com/problems/sales-analysis-iii/)|[Solution](../master/database/_1084.sql) | | Easy |
|1083|[Sales Analysis II](https://leetcode.com/problems/sales-analysis-ii/)|[Solution](../master/database/_1083.sql) | | Easy |
Expand Down
48 changes: 48 additions & 0 deletionsjavascript/_1146.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
/**
* Author: Phuong Lam
*/

/**
* @param {number} length
*/
var SnapshotArray = function (length) {
this.changes = {}
this.snapShots = []
}

/**
* @param {number} index
* @param {number} val
* @return {void}
*/
SnapshotArray.prototype.set = function (index, val) {
this.changes[index] = val
}

/**
* @return {number}
*/
SnapshotArray.prototype.snap = function () {
this.snapShots.push(this.changes)
this.changes = {}
return this.snapShots.length - 1
}

/**
* @param {number} index
* @param {number} snap_id
* @return {number}
*/
SnapshotArray.prototype.get = function (index, snap_id) {
while (snap_id >= 0 && this.snapShots[snap_id][index] === undefined) snap_id--
if (snap_id >= 0) return this.snapShots[snap_id][index]
return 0
}

/**
* Your SnapshotArray object will be instantiated and called as such:
* var obj = new SnapshotArray(length)
* obj.set(index,val)
* var param_2 = obj.snap()
* var param_3 = obj.get(index,snap_id)
*/

[8]ページ先頭

©2009-2025 Movatter.jp