Leetcode:73. 矩陣置零 阿新 • • 發佈:2018-12-18 class Solution{ public: void setZeroes(vector<vector<int>>& matrix) { int m = matrix.size(), n = matrix[0].size(); int i, j; for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { if (matrix[i - 1][j - 1] == 0) { x[i] = 1; y[j] = 1; } } } unordered_map<int, int>::iterator it; for (it = x.begin(); it != x.end(); it++) { matrix[it->first - 1] = vector<int>(n, 0); } for (it = y.begin(); it != y.end(); it++) { for (i = 1; i <= m; i++) { matrix[i - 1][it->first - 1] = 0; } } } private: unordered_map<int, int> x; unordered_map<int, int> y; };