Skip to content

Commit 29986b0

Browse files
edit 303
1 parent ff69318 commit 29986b0

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Your ideas/fixes/algorithms are more than welcome!
283283
|306|[Additive Number](https://leetcode.com/problems/additive-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_306.java)| O(n^2) | O(n) | Medium|
284284
|305|[Number of Islands II](https://leetcode.com/problems/number-of-islands-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/NumberofIslandsII.java)| ? | ? | Hard| Union Find
285285
|304|[Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/)|[Solution](../master/src/main/java/com/fishercoder/solutions/RangeSumQuery2DImmutable.java)| ? | ? |Medium|
286-
|303|[Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/)|[Solution](../master/src/main/java/com/fishercoder/solutions/RangeSumQueryImmutable.java)| O(n) | O(1) |Easy|
286+
|303|[Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_303.java)| O(n) | O(1) |Easy|
287287
|302|[Smallest Rectangle Enclosing Black Pixels](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_302.java)| ? | O(m*n) | Hard| DFS, BFS
288288
|301|[Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/RemoveInvalidParentheses.java)| ? | ? | Hard| BFS
289289
|300|[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_300.java)| O(logn)|O(n) | Medium| DP

src/main/java/com/fishercoder/solutions/RangeSumQueryImmutable.java renamed to src/main/java/com/fishercoder/solutions/_303.java

+16-19
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,28 @@
1111
Note:
1212
You may assume that the array does not change.
1313
There are many calls to sumRange function.*/
14-
public class RangeSumQueryImmutable {
15-
16-
17-
}
18-
19-
class NumArray {
20-
int[] sums;
21-
public NumArray(int[] nums) {
22-
sums = new int[nums.length];
23-
for(int i = 0; i < nums.length; i++){
24-
if(i == 0){
25-
sums[i] = nums[i];
26-
} else {
27-
sums[i] = sums[i-1] + nums[i];
14+
public class _303 {
15+
class NumArray {
16+
int[] sums;
17+
18+
public NumArray(int[] nums) {
19+
sums = new int[nums.length];
20+
for (int i = 0; i < nums.length; i++) {
21+
if (i == 0) {
22+
sums[i] = nums[i];
23+
} else {
24+
sums[i] = sums[i - 1] + nums[i];
25+
}
2826
}
2927
}
30-
}
3128

32-
public int sumRange(int i, int j) {
33-
if(i == 0) return sums[j];
34-
return sums[j] - sums[i-1];
29+
public int sumRange(int i, int j) {
30+
if (i == 0) return sums[j];
31+
return sums[j] - sums[i - 1];
32+
}
3533
}
3634
}
3735

38-
3936
// Your NumArray object will be instantiated and called as such:
4037
// NumArray numArray = new NumArray(nums);
4138
// numArray.sumRange(0, 1);

0 commit comments

Comments
 (0)