Leetcode 73

class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        vector<vector<int>> store;
        int m = matrix.size();
        int n = matrix[0].size();
        for(int i=0;i < m;i++){
            for(int j=0;j < n;j++){
                if(matrix[i][j] == 0){
                    vector<int> temp;
                    temp.push_back(i);
                    temp.push_back(j);
                    store.push_back(temp);
                    temp.clear();
                }
            }
        }
        for(int i=0;i < store.size();i++){
            int a = store[i][0];
            int b = store[i][1];
            for(int j=0;j < m;j++) matrix[j][b] = 0;
            for(int j=0;j < n;j++) matrix[a][j] = 0;
        }
    }
};

猜你喜欢

转载自www.cnblogs.com/cunyusup/p/9837488.html