File tree Expand file tree Collapse file tree 2 files changed +28
-30
lines changed
insufficient-nodes-in-root-to-leaf-paths Expand file tree Collapse file tree 2 files changed +28
-30
lines changed Original file line number Diff line number Diff line change 1
1
// +build ignore
2
2
3
3
#pragma once
4
- /* *
5
- * Definition for a binary tree node.
6
- * struct TreeNode {
7
- * int val;
8
- * TreeNode *left;
9
- * TreeNode *right;
10
- * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
11
- * };
12
- */
13
-
14
- // #include "../insert-into-a-binary-search-tree/TreeNode.hpp"
4
+
15
5
import leetcode_treenode_cpp.TreeNode;
16
6
using namespace leetcode_treenode_cpp ;
17
- class Solution {
18
- public:
19
- TreeNode* sufficientSubset (TreeNode* root, int limit)
7
+
8
+ namespace insufficient_nodes_in_root_to_leaf_paths
9
+ {
10
+ class Solution
20
11
{
12
+ public:
13
+ TreeNode *sufficientSubset (TreeNode *root, int limit)
14
+ {
21
15
22
- if (!root)
23
- return root;
16
+ if (!root)
17
+ return root;
24
18
25
- if (!root->left && !root->right ) {
19
+ if (!root->left && !root->right )
20
+ {
26
21
27
- if (root->val >= limit)
28
- return root;
22
+ if (root->val >= limit)
23
+ return root;
29
24
30
- else
31
- return nullptr ;
32
- }
25
+ else
26
+ return nullptr ;
27
+ }
33
28
34
- root->left = sufficientSubset (root->left , limit - root->val );
35
- root->right = sufficientSubset (root->right , limit - root->val );
29
+ root->left = sufficientSubset (root->left , limit - root->val );
30
+ root->right = sufficientSubset (root->right , limit - root->val );
36
31
37
- if (!root->left && !root->right )
38
- return nullptr ;
39
- else
40
- return root;
41
- }
42
- };
32
+ if (!root->left && !root->right )
33
+ return nullptr ;
34
+ else
35
+ return root;
36
+ }
37
+ };
38
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ using namespace leetcode_treenode_cpp;
14
14
import leetcode_treenode_cpp.traversalTreeNode;
15
15
import leetcode_treenode_cpp.LeetCodeTreeNodeToString;
16
16
import leetcode_treenode_cpp.parseLeetCodeBinaryTree;
17
+
18
+ using namespace insufficient_nodes_in_root_to_leaf_paths ;
17
19
void LeetCode1080TestExamples (std::string& root, int limit, std::string& output)
18
20
{
19
21
TreeNode* tree = nullptr ;
You can’t perform that action at this time.
0 commit comments