Skip to content

Commit e46eb8f

Browse files
committed
add 100, 231
1 parent 793fc01 commit e46eb8f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

0100-same-tree.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
100. Same Tree
3+
4+
Submitted: December 9, 2024
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 12.76 MB (beats 15.77%)
8+
*/
9+
10+
/**
11+
* Definition for a binary tree node.
12+
* struct TreeNode {
13+
* int val;
14+
* TreeNode *left;
15+
* TreeNode *right;
16+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
17+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
18+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
19+
* };
20+
*/
21+
class Solution {
22+
public:
23+
bool isSameTree(TreeNode* p, TreeNode* q) {
24+
if (p == nullptr || q == nullptr) return p == q;
25+
if (p->val != q->val) return false;
26+
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
27+
}
28+
};

0231-power-of-two.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
231. Power of Two
3+
4+
Solved: December 9, 2024
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 7.84 MB (beats 10.33%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
bool isPowerOfTwo(int n) {
13+
if (n <= 0) return false;
14+
return !(n & (n - 1));
15+
}
16+
};

0 commit comments

Comments
 (0)