Skip to content

Commit c635289

Browse files
committed
2331 added.
1 parent 394b4e1 commit c635289

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(A)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(A main.cpp)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/// Source : https://leetcode.com/problems/evaluate-boolean-binary-tree/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-09
4+
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
10+
/// DFS
11+
/// Time Complexity: O(n)
12+
/// Space Complexity: O(h)
13+
14+
/// Definition for a binary tree node.
15+
struct TreeNode {
16+
int val;
17+
TreeNode *left;
18+
TreeNode *right;
19+
TreeNode() : val(0), left(nullptr), right(nullptr) {}
20+
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
21+
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
22+
};
23+
24+
class Solution {
25+
public:
26+
bool evaluateTree(TreeNode* root) {
27+
28+
if(root->left == nullptr || root->right == nullptr)
29+
return root->val;
30+
31+
int a = evaluateTree(root->left);
32+
int b = evaluateTree(root->right);
33+
34+
if(root->val == 2) return a | b;
35+
return a & b;
36+
}
37+
};
38+
39+
40+
int main() {
41+
42+
return 0;
43+
}

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,9 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
21752175
| 2326 | [Spiral Matrix IV](https://leetcode.com/problems/spiral-matrix-iv/) | [] | [C++](2001-2500/2326-Spiral-Matrix-IV/cpp-2326/) | | |
21762176
| 2327 | [Number of People Aware of a Secret](https://leetcode.com/problems/number-of-people-aware-of-a-secret/) | [] | [C++](2001-2500/2327-Number-of-People-Aware-of-a-Secret/cpp-2327/) | | |
21772177
| 2328 | [Number of Increasing Paths in a Grid](https://leetcode.com/problems/number-of-increasing-paths-in-a-grid/) | [] | [C++](2001-2500/2328-Number-of-Increasing-Paths-in-a-Grid/cpp-2328/) | | |
2178+
| 2329 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
2179+
| | | | | | |
2180+
| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/) | [] | [C++](2001-2500/2331-Evaluate-Boolean-Binary-Tree/cpp-2331/) | | |
21782181
| | | | | | |
21792182
| 2333 | [Minimum Sum of Squared Difference](https://leetcode.com/problems/minimum-sum-of-squared-difference/) | [] | [C++](2001-2500/2333-Minimum-Sum-of-Squared-Difference/cpp-2333/) | | |
21802183
| 2334 | [Subarray With Elements Greater Than Varying Threshold](https://leetcode.com/problems/subarray-with-elements-greater-than-varying-threshold/) | [] | [C++](2001-2500/2334-Subarray-With-Elements-Greater-Than-Varying-Threshold/cpp-2334/) | | |

0 commit comments

Comments
 (0)