Question: class Solution: def find _ path _ sum _ to _ k ( self , root: Optional [ TreeNode ] , k: int ) -

class Solution:
def find_path_sum_to_k(self, root: Optional[TreeNode], k: int)-> bool:
if not root:
return False
if root.val == k and not root.left and not root.right:
return True
return self.find_path_sum_to_k(root.left, k - root.val) or self.find_path_sum_to_k(root.right, k - root.val)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!