C++ two one-line functions


  • -1
    class Solution {
    private:
        int pathSum(TreeNode* root, int target, int sum) {
            return root ? ((sum += root->val) == target) + pathSum(root->left, target, sum) + pathSum(root->right, target, sum) : 0;
        }
    public:
        int pathSum(TreeNode* root, int sum) {
            return root ? pathSum(root, sum, 0) + pathSum(root->left, sum) + pathSum(root->right, sum) : 0;
        }
    };
    

Log in to reply
 

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