Relative Content

Tag Archive for ctree

just want to know is this possible to compile and run test case with this code and this code fails when i try to submit it for other test cases

class Solution
{
private:
void helper(Node* root,vector& ans){
if(root == nullptr){
return;
}
helper(root->left,ans);
ans.push_back(root->data);
helper(root->right,ans);
}
public:
//Function to check if two trees are identical.
bool isIdentical(Node *r1, Node *r2)
{
vector ans1;
vector ans2;
helper(r1,ans1);
helper(r2,ans2);
int n = ans1.size();
int m = ans2.size();
if(n != m) return false;
for(int i = 0;i<n;i++){
if(ans1[i] != ans2[i]){
return false;
}
}
return true;
}
};