目录
思路:
1递归
思路:
1递归
递归函数声明:
bool hasPathSum(TreeNode* root, int targetSum);
递归出口:
如果根节点为空, 返回假
如果只有根节点, 当根节点值为targetsum时返回真,否则返回假
递归体:
考虑左子树和右子树的路径和
递归判断左子树或右子树路径和是否可能为targetsum-root->val
目录
思路:
1递归
递归函数声明:
bool hasPathSum(TreeNode* root, int targetSum);
递归出口:
如果根节点为空, 返回假
如果只有根节点, 当根节点值为targetsum时返回真,否则返回假
递归体:
考虑左子树和右子树的路径和
递归判断左子树或右子树路径和是否可能为targetsum-root->val