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); +}