Saved Bookmarks
| 1. |
Write a function to print all unique rows of the given matrix. |
|
Answer» Input: {{1, 1, 1, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 1, 1, 0}, {0, 1, 0, 0, 1}, {1, 1, 1, 0, 0}}
{{1, 1, 1, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 1, 1, 0}} vector<vector<int>> uniqueRow(int M[MAX][MAX],int row,int col){ set<vector<int>> st; vector<vector<int>> v; for(int i=0; i<row; i++) { vector<int> v1; for(int j=0; j<col; j++) { v1.push_back(M[i][j]); } if(st.count(v1) == 0) { v.push_back(v1); st.insert(v1); } } return v; }
|
|