Skip to content

Commit

Permalink
a303
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhengwei committed Jan 12, 2017
1 parent 223165d commit fb7769d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ leetcode 题解

[295. Find Median from Data Stream](Solution/251-300/295.md)

[303. Range Sum Query - Immutable](Solution/301-350/303.md)

[326. Power of Three](Solution/301-350/326.md)

[342. Power of Four](Solution/301-350/342.md)
Expand Down
22 changes: 22 additions & 0 deletions Solution/301-350/303.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#303. Range Sum Query - Immutable
[题目链接](https://leetcode.com/problems/range-sum-query-immutable/)
```java
public class NumArray {

private int[] nums;
public NumArray(int[] nums) {
// 预处理
for (int i=1; i < nums.length; i++) {
nums[i] += nums[i - 1];
}
this.nums = nums;
}

public int sumRange(int i, int j) {
if (i == 0) {
return nums[j];
}
return nums[j] - nums[i - 1];
}
}
```

0 comments on commit fb7769d

Please sign in to comment.