Grokking the Engineering Manager Coding Interview
0% completed
Path With Given Sequence (medium)
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 3 years ago
#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): # TODO: Write your code here return self.findPath_helper(root, sequence, []) def findPath_helper(self, root, sequence, currList): if root is None: return False currList.append(root.val) print(currList) if currList == sequence and root.left is None and root.right is None: return True exist_left = self.findPath_helper(root.left, sequence, currList) exist_right = self.findPath_helper(root.right, sequence, currList) del currList[-1] return exist_left | exist_right
Reading Progress
0%