From f9677302d91ae7265a93dafbd652f4fc86f6aab0 Mon Sep 17 00:00:00 2001 From: parth-6945 <140963864+parth-6945@users.noreply.github.com> Date: Sun, 6 Apr 2025 12:24:36 +0530 Subject: [PATCH] feat: add LeetCode problem 100 - Same Tree --- leetcode/src/100.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 leetcode/src/100.c diff --git a/leetcode/src/100.c b/leetcode/src/100.c new file mode 100644 index 0000000000..44067dab29 --- /dev/null +++ b/leetcode/src/100.c @@ -0,0 +1,27 @@ +/** + * LeetCode Problem 100 - Same Tree + * Check if two binary trees are the same. + * + * Two binary trees are the same if they are structurally identical and the nodes have the same value. + */ + +/** + * Definition for a binary tree node: + * struct TreeNode { + * int val; + * struct TreeNode *left; + * struct TreeNode *right; + * }; + */ + + bool isSameTree(struct TreeNode* p, struct TreeNode* q) { + if (p == NULL && q == NULL) { + return true; + } + if (p == NULL || q == NULL) { + return false; + } + return (p->val == q->val) && + isSameTree(p->left, q->left) && + isSameTree(p->right, q->right); +}