Skip to content

Commit 4b4df32

Browse files
author
Rich Vigorito
committed
feat: add LeetCode problem 100
Check for tree equivalence
1 parent e5dad3f commit 4b4df32

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

leetcode/src/100.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* 100. Same Tree
3+
* https://leetcode.com/problems/same-tree/
4+
*
5+
* Given the roots of two binary trees p and q, write a function to check if they are the same or not.
6+
* Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
7+
*
8+
*/
9+
10+
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
11+
if (p == NULL && q == NULL) return true;
12+
if (p == NULL || q == NULL) return false;
13+
if (p->val != q->val) return false;
14+
15+
return isSameTree(p->left, q->left)
16+
&& isSameTree(p->right, q->right);
17+
}

0 commit comments

Comments
 (0)