Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Kyle Alberry
Python solution with no recursion. Just a simple while loop.

Kyle Alberry

Jan 7, 2025

#class TreeNode: #  def __init__(self, val, left=None, right=None): #    self.val = val #    self.left = left #    self.right = right class Solution:   def findPath(self, root, sequence):     dummy = TreeNode(-1,root)     cur = dummy     for num in sequence:       if cur.left and num == cur.left.val:         cur = cur.left       elif cur.right and num == cur.right.val:         cur = cur.right       else:         return False     if not cur.left and not cur.right:       return True     return False

0

0

Comments
Comments

On this page