Leetcode_Path Sum

来源:互联网 发布:淘宝信用卡套现店铺 编辑:程序博客网 时间:2024/06/01 16:29
递归实现即可
class Solution {public:    bool hasPathSum(TreeNode *root, int sum) {if(!root)return false;if(root->left ==nullptr&&root->right==nullptr&&root->val==sum)return true;return hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val);            }};

0 0
原创粉丝点击