Skip to content

Commit 708b2db

Browse files
committed
complete 100
1 parent 14bdfda commit 708b2db

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"ostream": "cpp",
4646
"stdexcept": "cpp",
4747
"streambuf": "cpp",
48-
"typeinfo": "cpp"
48+
"typeinfo": "cpp",
49+
"bitset": "cpp"
4950
}
5051
}

100.same-tree.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @lc app=leetcode id=100 lang=cpp
3+
*
4+
* [100] Same Tree
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* Definition for a binary tree node.
10+
* struct TreeNode {
11+
* int val;
12+
* TreeNode *left;
13+
* TreeNode *right;
14+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
15+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17+
* };
18+
*/
19+
class Solution {
20+
public:
21+
bool isSameTree(TreeNode* p, TreeNode* q) {
22+
if (p==NULL&&q==NULL)return true;
23+
if (p!=NULL&&q==NULL
24+
|| p==NULL&&q!=NULL)return false;
25+
26+
return p->val == q->val
27+
&& isSameTree(p->left , q->left)
28+
&& isSameTree(p->right, q->right);
29+
}
30+
};
31+
// @lc code=end
32+

0 commit comments

Comments
 (0)