one line c++ solution


  • 0
    P

    class Solution {
    public:
    bool hasPathSum(TreeNode* root, int sum)
    {
    return root?(sum==root->val&&!root->left&&!root->right) || hasPathSum(root->left, sum-root->val) || hasPathSum(root->right, sum-root->val):0;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.