class Solution {
public:
vector<vector<int>> modifiedMatrix(vector<vector<int>>& matrix) {
vector<vector<int>> ans = matrix;
map<int, int> map;
for (int col = 0; col < ans[0].size(); col++) {
int maxValue = -1;
for (int row = 0; row < ans.size(); row++) {
//store position of elem '-1'
if (ans[row][col] == -1) {
map.insert(pair<int, int>(row, col));
}
//get max value of this col
if (ans[row][col] > maxValue) {
maxValue = ans[row][col];
}
}
//change the value of elem '-1'
for (auto& elem : map) {
ans[elem.first][elem.second] = maxValue;
}
map.clear();
}
return ans;
}
};
LeetCode3033.修改矩阵
最新推荐文章于 2024-09-14 22:25:23 发布