leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2536.cpp (831B)


0 class Solution { 1 public: 2 vector<vector<int>> rangeAddQueries(int n, const vector<vector<int>> &queries) const { 3 vector<vector<int>> mat(n, vector(n, 0)); 4 5 for (const auto &query : queries) { 6 mat[query[0]][query[1]]++; 7 if (query[2] + 1 < n && query[3] + 1 < n) mat[query[2] + 1][query[3] + 1]++; 8 if (query[2] + 1 < n) mat[query[2] + 1][query[1]]--; 9 if (query[3] + 1 < n) mat[query[0]][query[3] + 1]--; 10 } 11 12 for (int i = 0; i < n; i++) { 13 for (int j = 0, acc = 0; j < n; j++) { 14 mat[i][j] = acc += mat[i][j]; 15 } 16 } 17 18 for (int j = 0; j < n; j++) { 19 for (int i = 0, acc = 0; i < n; i++) { 20 mat[i][j] = acc += mat[i][j]; 21 } 22 } 23 24 return mat; 25 } 26 };