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 4b4df32Copy full SHA for 4b4df32
leetcode/src/100.c
@@ -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