class Solution { public: //Function to modify the matrix such that if a matrix cell matrix[i][j] //is 1 then all the cells in its ith row and jth column will become 1. void booleanMatrix(vector<vector<int> > &matrix) { int n1=matrix.size(); int n2=matrix[0].size(); vector<pair<int,int>> v; for(int i=0;i<n1;i++) { for(int j=0;j<n2;j++) { if(matrix[i][j]==1) { v.push_back({i,j}); } } } int n3=v.size(); for(int i=0;i<n3;i++) { for(int j=0;j<n2;j++) { matrix[v[i].first][j]=1; } for(int j=0;j<n1;j++) { matrix[j][v[i].second]=1; } } } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter