# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isValidSequence(self, root: TreeNode, arr: List[int]) -> bool:
if len(arr)>0 and root is None:
return False
if root.val!=arr[0]:
return False
arr=arr[1:]
if len(arr)==0:
if root.left==None and root.right==None:
return True
else:
return False
return self.isValidSequence(root.left,arr) or self.isValidSequence(root.right,arr)