File tree 2 files changed +17
-20
lines changed
src/main/java/com/fishercoder/solutions
2 files changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -283,7 +283,7 @@ Your ideas/fixes/algorithms are more than welcome!
283
283
| 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|
284
284
|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
285
285
| 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|
287
287
|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
288
288
|301|[ Remove Invalid Parentheses] ( https://leetcode.com/problems/remove-invalid-parentheses/ ) |[ Solution] ( ../master/src/main/java/com/fishercoder/solutions/RemoveInvalidParentheses.java ) | ? | ? | Hard| BFS
289
289
|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
Original file line number Diff line number Diff line change 11
11
Note:
12
12
You may assume that the array does not change.
13
13
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
+ }
28
26
}
29
27
}
30
- }
31
28
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
+ }
35
33
}
36
34
}
37
35
38
-
39
36
// Your NumArray object will be instantiated and called as such:
40
37
// NumArray numArray = new NumArray(nums);
41
38
// numArray.sumRange(0, 1);
You can’t perform that action at this time.
0 commit comments