三天都寫一寫
寫得滿手是血
我好爛...姆咪...
def dfs(self, head, root):
if head is None:
return True
if root is None:
return False
if head.val == root.val:
return self.dfs(head.next, root.left) or self.dfs(head.next,
root.right)
else:
return False
def isSubPath(self, head: Optional[ListNode], root: Optional[TreeNode]) ->
bool:
if root is None:
return False
elif self.dfs(head,root):
return True
else:
return self.isSubPath(head,root.left) or
self.isSubPath(head,root.right)