From c95af2a563f34be7bdb211348534f6c3b4f45909 Mon Sep 17 00:00:00 2001 From: Ravi Menariya <112074438+ravimenariya@users.noreply.github.com> Date: Tue, 21 Nov 2023 21:40:16 +0530 Subject: [PATCH] Create 21-Nov_identical_tree.cpp 21-Nov Done --- 11-2023(nov)/21-Nov_identical_tree.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 11-2023(nov)/21-Nov_identical_tree.cpp diff --git a/11-2023(nov)/21-Nov_identical_tree.cpp b/11-2023(nov)/21-Nov_identical_tree.cpp new file mode 100644 index 0000000..dbc2e89 --- /dev/null +++ b/11-2023(nov)/21-Nov_identical_tree.cpp @@ -0,0 +1,19 @@ +class Solution +{ + public: + //Function to check if two trees are identical. + bool isIdentical(Node *r1, Node *r2) + { + //Your Code here + if (!r1 && !r2) { + return true; + } + + if (r1 && r2 && r1->data == r2->data) { + return isIdentical(r1->left, r2->left) && + isIdentical(r1->right, r2->right); + } + + return false; + } +};