Linked List in Binary Tree LeetCode solution in Python

1
# Runtime: 139 ms (Top 73.10%) | Memory: 16.3 MB (Top 54.16%)
2

3

4
class Solution(object):
5
def isSubPath(self, head, root):
6
if not root:
7
return False
8
if self.issame(head, root):
9
return True
10
return self.isSubPath(head, root.left) or self.isSubPath(head, root.right)
11

12
def issame(self, head, root):
13
if not head:
14
return True
15
if not root:
16
return False
17
if head.val != root.val:
18
return False
19
return self.issame(head.next, root.left) or self.issame(head.next, root.right)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0