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

Commit9148768

Browse files
authored
Merge pull requestneetcode-gh#2541 from aadil42/patch-43
Create 0303-range-sum-query-immutable.js
2 parents9ea6870 +1b4919f commit9148768

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* https://leetcode.com/problems/range-sum-query-immutable/
3+
*@param {number[]} nums
4+
*/
5+
classNumArray{
6+
constructor(nums){
7+
this.arr=nums;
8+
}
9+
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;
22+
}
23+
}
24+
25+
/**
26+
* Your NumArray object will be instantiated and called as such:
27+
* var obj = new NumArray(nums)
28+
* var param_1 = obj.sumRange(left,right)
29+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp