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

Commit1b4919f

Browse files
authored
Update 0303-range-sum-query-immutable.js
Converted to class based.
1 parentcaef263 commit1b4919f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

‎javascript/0303-range-sum-query-immutable.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/**
2+
* https://leetcode.com/problems/range-sum-query-immutable/
23
*@param {number[]} nums
34
*/
4-
varNumArray=function(nums){
5-
this.arr=nums;
6-
};
5+
classNumArray{
6+
constructor(nums){
7+
this.arr=nums;
8+
}
79

8-
/**
9-
* https://leetcode.com/problems/range-sum-query-immutable/description/
10-
* Time O(n) | Space O(1)
11-
*@param {number}left
12-
*@param {number} right
13-
*@return {number}
14-
*/
15-
NumArray.prototype.sumRange=function(left,right){
16-
17-
lettotal=0;
18-
for(leti=left;i<right+1;i++){
19-
total+=this.arr[i];
10+
/**
11+
* Time O(n) | Space O(1)
12+
*@param {number} left
13+
*@param {number}right
14+
*@return {number}
15+
*/
16+
sumRange(left,right){
17+
lettotal=0;
18+
for(leti=left;i<right+1;i++){
19+
total+=this.arr[i];
20+
}
21+
returntotal;
2022
}
21-
returntotal
22-
};
23+
}
2324

2425
/**
2526
* Your NumArray object will be instantiated and called as such:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp