文章目录
- 1. 题目
- 2. 解题
1. 题目
输入:
2
2
[[1,3],[4,10]]
输出: [[1,2],[3,4]]Explanation:
before:
1 2
3 4after:
1 3
4 10
https://tianchi.aliyun.com/oj/286606814880453210/327250187142763355
2. 解题
- 前缀和逆运算
class Solution {
public:/*** @param n: the row of the matrix* @param m: the column of the matrix* @param after: the matrix* @return: restore the matrix*/vector<vector<int>> matrixRestoration(int n, int m, vector<vector<int>> &after) {// write your code herefor(int i = n-1; i >= 0; --i){for(int j = m-1; j >= 0; --j){after[i][j] = after[i][j]-(j>0 ? after[i][j-1] : 0)-(i>0 ? after[i-1][j] : 0)+(i>0&&j>0? after[i-1][j-1] : 0);}}return after;}
};
50ms C++
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!