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

Commit90a8f54

Browse files
authored
Merge pull requestneetcode-gh#2409 from Saiteja-Basam/master
Create 0303-range-sum-query-immutable.java
2 parents3b58717 +e7b43fb commit90a8f54

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classNumArray {
2+
3+
publicint[]arr;
4+
publicNumArray(int[]nums) {
5+
arr=nums;
6+
for(inti=1;i<arr.length;i++){
7+
arr[i]+=arr[i-1];
8+
}
9+
}
10+
11+
publicintsumRange(intleft,intright) {
12+
if(left==0){
13+
returnarr[right];
14+
}
15+
returnarr[right]-arr[left-1];
16+
}
17+
}
18+
19+
/**
20+
* Your NumArray object will be instantiated and called as such:
21+
* NumArray obj = new NumArray(nums);
22+
* int param_1 = obj.sumRange(left,right);
23+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp