-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14jan_trie.cpp
131 lines (104 loc) · 2.85 KB
/
14jan_trie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Author : Manas Rawat
Date : 14/01/2024
Problem : Find duplicate rows in a binary matrix
Difficulty : Medium
Problem Link : https://www.geeksforgeeks.org/problems/find-duplicate-rows-in-a-binary-matrix/1
Video Solution : https://youtu.be/btb4KVCJuqw
*/
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class node {
public:
vector<node*> next;
node() {
next = vector<node*> (2, nullptr);
}
};
class Solution
{
public:
// vector<int> repeatedRows(vector<vector<int>> &matrix, int M, int N)
// {
// swap(N, M);
// node * root = new node();
// vector<int> ans;
// auto insert = [&](vector<int> &row) {
// node * cur = root;
// for(int i = 0; i < M; i++){
// if(cur -> next[row[i]] != nullptr){
// cur = cur -> next[row[i]];
// }
// else{
// node * newnode = new node();
// cur -> next[row[i]] = newnode;
// cur = newnode;
// }
// }
// };
// auto find = [&](vector<int> &row) -> bool {
// node * cur = root;
// for(int i = 0; i < M; i++){
// if(cur -> next[row[i]] != nullptr){
// cur = cur -> next[row[i]];
// }
// else{
// return 0;
// }
// }
// return 1;
// };
// for(int i = 0; i < N; i++){
// if(!find(matrix[i])){
// insert(matrix[i]);
// }
// else
// ans.push_back(i);
// }
// return ans;
// }
vector<int> repeatedRows(vector<vector<int>> &matrix, int M, int N)
{
// Your code here
map<vector<int>,int> f;vector<int> ans;
for(int i=0;i<matrix.size();i++)
{
if(f.find(matrix[i])==f.end())
f[matrix[i]]=1;
else
ans.push_back(i);
}
return ans;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin>>t;
while(t--)
{
int row, col;
cin>> row>> col;
vector<vector<int> > matrix(row);
for(int i=0; i<row; i++)
{
matrix[i].assign(col, 0);
for( int j=0; j<col; j++)
{
cin>>matrix[i][j];
}
}
Solution ob;
vector<int> ans = ob.repeatedRows(matrix, row, col);
for (int i = 0; i < ans.size(); ++i)
{
cout<<ans[i]<<" ";
}
cout<<endl;
}
return 0;
}
// } Driver Code Ends