Back to course home
0% completed
Vote For New Content
Python3 Solution
Thai Minh
Oct 29, 2023
#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
0
0
Comments
Comments
On this page