Given a 0-indexedm x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column.
Return the matrixanswer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution { public: vector<vector<int>> modifiedMatrix(vector<vector<int>>& A) { int n = A.size(), m = A[0].size(); vector<int> ma(m); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { ma[j] = max(ma[j], A[i][j]); } for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { if(A[i][j] == -1) A[i][j] = ma[j]; } return A; } };