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

Commit5970bc2

Browse files
authored
Add solution for problem 1146 (fishercoder1534#128)
* Add solution for problem 1146 in Javascript* Add js file
1 parentf974325 commit5970bc2

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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|

‎javascript/_1146.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Author: Phuong Lam
3+
*/
4+
5+
/**
6+
*@param {number} length
7+
*/
8+
varSnapshotArray=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+
returnthis.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)returnthis.snapShots[snap_id][index]
39+
return0
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+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp