Skip to content

Commit f967730

Browse files
committed
feat: add LeetCode problem 100 - Same Tree
1 parent e5dad3f commit f967730

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

leetcode/src/100.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* LeetCode Problem 100 - Same Tree
3+
* Check if two binary trees are the same.
4+
*
5+
* Two binary trees are the same if they are structurally identical and the nodes have the same value.
6+
*/
7+
8+
/**
9+
* Definition for a binary tree node:
10+
* struct TreeNode {
11+
* int val;
12+
* struct TreeNode *left;
13+
* struct TreeNode *right;
14+
* };
15+
*/
16+
17+
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
18+
if (p == NULL && q == NULL) {
19+
return true;
20+
}
21+
if (p == NULL || q == NULL) {
22+
return false;
23+
}
24+
return (p->val == q->val) &&
25+
isSameTree(p->left, q->left) &&
26+
isSameTree(p->right, q->right);
27+
}

0 commit comments

Comments
 (0)