Problem:
思路:
Solution (C++):
bool hasPathSum(TreeNode* root, int sum) {
if (root == NULL) return false;
if (root->val == sum && !root->left && !root->right) return true;
return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val);
}
性能:
Runtime: 8 ms Memory Usage: 19.9 MB