ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
Solution Function Link: ide.geeksforgeeks.org/online-cpp-compiler/f478cf93-68c8-4518-9b1f-d4de3c73bfe2
Bdhia bhai
Use this method instead string solve(Node* root,unordered_map &mp){ if(root == NULL) return "N"; if(root->left == NULL && root->right == NULL){ string s = to_string(root->data); return s; } string s = to_string(root->data) + "," + solve(root->left,mp) + "," + solve(root->right,mp); mp[s]++; return s; } int dupSub(Node *root) { unordered_map mp; solve(root,mp); for(auto i:mp){ if(i.second > 1) return 1; } return 0; }
Solution Function Link: ide.geeksforgeeks.org/online-cpp-compiler/f478cf93-68c8-4518-9b1f-d4de3c73bfe2
Bdhia bhai
Use this method instead
string solve(Node* root,unordered_map &mp){
if(root == NULL) return "N";
if(root->left == NULL && root->right == NULL){
string s = to_string(root->data);
return s;
}
string s = to_string(root->data) + "," + solve(root->left,mp) + "," + solve(root->right,mp);
mp[s]++;
return s;
}
int dupSub(Node *root) {
unordered_map mp;
solve(root,mp);
for(auto i:mp){
if(i.second > 1) return 1;
}
return 0;
}