验证中...
助力高校计算机教育 —— 码云为老师推出免费高校版,高达 200 人的协作团队
gistfile1.txt
Raw Copy
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool hasPathSum(TreeNode* root, int sum) {
if(!root) return false;
if(!root->left&&!root->right&&!(root->val-sum)) return true;
sum-=root->val;
return hasPathSum(root->left,sum)||hasPathSum(root->right,sum);
}
};

Comment list( 0 )

You need to Sign in for post a comment

10_float_left_people 10_float_left_close