old_contents: """Leetcode 112. Path Sum
  Easy
  
  URL: https://leetcode.com/problems/path-sum/
  
  Given a binary tree and a sum, determine if the tree has a root-to-leaf path
  such that adding up all the values along the path equals the given sum.
  
  Note: A leaf is a node with no children.
  
  Example:
  Given the below binary tree and sum = 22,
        5
       / \
      4   8
     /   / \
    11  13  4
   /  \      \
  7    2      1
  return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
  """
  
  # Definition for a binary tree node.
  class TreeNode(object):
      def __init__(self, val):
          self.val = val
          self.left = None
          self.right = None
  
  
  class Solution(object):
      def hasPathSum(self, root, sum):
          """
          :type root: TreeNode
          :type sum: int
          :rtype: bool
          """
          pass
  
  
  def main():
      pass
  
  
  if __name__ == '__main__':
      main()
  
new_contents: """Leetcode 112. Path Sum
  Easy
  
  URL: https://leetcode.com/problems/path-sum/
  
  Given a binary tree and a sum, determine if the tree has a root-to-leaf path
  such that adding up all the values along the path equals the given sum.
  
  Note: A leaf is a node with no children.
  
  Example:
  Given the below binary tree and sum = 22,
        5
       / \
      4   8
     /   / \
    11  13  4
   /  \      \
  7    2      1
  return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
  """
  
  # Definition for a binary tree node.
  class TreeNode(object):
      def __init__(self, val):
          self.val = val
          self.left = None
          self.right = None
  
  
  class SolutionRecur(object):
      def hasPathSum(self, root, sum):
          """
          :type root: TreeNode
          :type sum: int
          :rtype: bool
          """
          if not root:
              return False
  
          if not root.left and not root.right and root.val == sum:
              return True
  
          return (self.hasPathSum(root.left, sum - root.val) or
                  self.hasPathSum(root.right, sum - root.val))
  
  
  def main():
      # Given the below binary tree and sum = 22,
      #       5
      #      / \
      #     4   8
      #    /   / \
      #   11  13  4
      #  /  \      \
      # 7    2      1
      # return true, 
      root = TreeNode(5)
      root.left = TreeNode(4)
      root.right = TreeNode(8)
      root.left.left = TreeNode(11)
      root.right.left = TreeNode(13)
      root.right.right = TreeNode(4)
      root.left.left.left = TreeNode(7)
      root.left.left.right = TreeNode(2)
      root.right.right.right = TreeNode(1)
      sum = 22
      print SolutionRecur().hasPathSum(root, sum)
  
  
  if __name__ == '__main__':
      main()
  
subject: Complete recur sol