Skip to content

Commit ed6ed13

Browse files
authored
Update 0304-range-sum-query-2d-immutable.js
Converted to Class based.
1 parent 4558e6c commit ed6ed13

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

javascript/0304-range-sum-query-2d-immutable.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
/**
22
* https://leetcode.com/problems/range-sum-query-2d-immutable/
3+
* @class NumMatrix
34
* @param {number[][]} matrix
45
*/
5-
var NumMatrix = function(matrix) {
6+
class NumMatrix {
7+
constructor(matrix) {
68
this.matrix = matrix;
7-
};
9+
}
810

9-
/**
10-
*
11-
* m = row2 - row1; n = col2 - col1
12-
* Time O(m*n) | Space O(1)
13-
* @param {number} row1
14-
* @param {number} col1
15-
* @param {number} row2
16-
* @param {number} col2
17-
* @return {number}
18-
*/
19-
NumMatrix.prototype.sumRegion = function(row1, col1, row2, col2) {
11+
/**
12+
*
13+
* m = row2 - row1; n = col2 - col1
14+
* Time O(m*n) | Space O(1)
15+
* @param {number} row1
16+
* @param {number} col1
17+
* @param {number} row2
18+
* @param {number} col2
19+
* @return {number}
20+
*/
21+
sumRegion(row1, col1, row2, col2) {
2022
let sum = 0;
21-
for(let i = row1; i < row2 + 1; i++) {
22-
for(let j = col1; j < col2 + 1; j++) {
23-
sum += this.matrix[i][j];
24-
}
23+
for (let i = row1; i < row2 + 1; i++) {
24+
for (let j = col1; j < col2 + 1; j++) {
25+
sum += this.matrix[i][j];
26+
}
2527
}
2628
return sum;
27-
};
29+
}
30+
}
2831

2932
/**
3033
* Your NumMatrix object will be instantiated and called as such:

0 commit comments

Comments
 (0)