一、计算布尔二叉树的值 . - 力扣(LeetCode) class Solution { public: bool evaluateTree(TreeNode* root) { if(root->left==nullptr) return root->val==0?false:true; bool left= evaluateTree(root->left); bool right=evaluateTree(root->right); return root->val==2?left||right:left&&right; //直接return root->val==2?evaluateTree(root->left)||evaluateTree(root->right):evaluateTree(root->left)&&evaluateTree(root->right) 会导致递归的时间变长,因为我们没有去记住返回值,所以一旦需要就得重新递归回去计算 } }; 二、求根节点到叶节点的数字之和 .
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with int
Contact int, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack