输入:
2
2
[[1,3],[4,10]]
输出: [[1,2],[3,4]]
Explanation:
before:
1 2
3 4
after:
1 3
4 10
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++