天池 在线编程 矩阵还原(前缀和)
作者:互联网
文章目录
1. 题目
输入:
2
2
[[1,3],[4,10]]
输出: [[1,2],[3,4]]
Explanation:
before:
1 2
3 4
after:
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 here
for(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阿明),一起加油、一起学习进步!
标签:after,前缀,int,编程,param,vector,https,天池,matrix 来源: https://blog.csdn.net/qq_21201267/article/details/113973027