-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_06.py
26 lines (26 loc) · 901 Bytes
/
Day_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def isSubPath(self, head, root):
def dfs(head , root) :
if not head :
return True
if not root :
return False
if head.val != root.val:
return False
return dfs(head.next , root.right) or dfs(head.next , root.left)
if not head:
return True
if not root :
return False
return dfs(head , root) or self.isSubPath(head , root.left) or self.isSubPath(head , root.right)