Skip to content

Commit cf22fec

Browse files
authored
Update range-sum-query-2d-immutable.cpp
1 parent 8277272 commit cf22fec

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

C++/range-sum-query-2d-immutable.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ class NumMatrix {
1414
sums_.emplace_back(n + 1, 0);
1515
}
1616
for (int i = 1; i <= m; ++i) {
17-
for (int j = 0; j <= n; ++j) {
18-
sums_[i][j] = sums_[i][j - 1] + matrix[i - 1][j - 1];
19-
}
20-
}
21-
for (int j = 0; j <= n; ++j) {
22-
for (int i = 1; i <= m; ++i) {
23-
sums_[i][j] += sums_[i - 1][j];
17+
for (int j = 1; j <= n; ++j) {
18+
sums_[i][j] = sums_[i][j - 1] + sums_[i - 1][j] -
19+
sums_[i - 1][j - 1] + matrix[i - 1][j - 1];
2420
}
2521
}
2622
}

0 commit comments

Comments
 (0)