SDE Sheet : #1.1
Ankit Rattan

Ankit Rattan @ankit_rattan

About: Developer | NIT Delhi'26 | Coder By Profession, Creator By Mind!

Joined:
Aug 21, 2024

SDE Sheet : #1.1

Publish Date: May 23
0 0

Ques : Set Matrix Zeroes
Leetcode number 73

Image description

class Solution {
public:
void solve(unordered_map<int, bool>row, unordered_map<int, bool>col, vector<vector<int>>&matrix){
    for(auto i = 0; i<matrix.size(); i++){
        for(auto j = 0; j<matrix[0].size(); j++){
            if(row[i] || col[j]){
            cout<<"row: "<<i<<" "<<"col: "<<j<<endl;
                matrix[i][j] = 0;
            }
        }
    }
}
    void setZeroes(vector<vector<int>>& matrix) {
        unordered_map<int, bool>row;
        unordered_map<int, bool>col;
        for(auto i = 0; i<matrix.size(); i++){
            for(auto j =0; j<matrix[0].size(); j++){
                if(matrix[i][j] == 0){
                    row[i] = true;
                    col[j] = true;
                }
            }
        }
        solve(row, col, matrix);
    }
};
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment