We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5dad3f commit f967730Copy full SHA for f967730
leetcode/src/100.c
@@ -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