def has_path_sum(root, sum):
if root is None:<EOL><INDENT>return False<EOL><DEDENT>if root.left is None and root.right is None and root.val == sum:<EOL><INDENT>return True<EOL><DEDENT>sum -= root.val<EOL>return has_path_sum(root.left, sum) or has_path_sum(root.right, sum)<EOL>
:type root: TreeNode
:type sum: int
:rtype: bool