Skip to content

Commit 6613620

Browse files
committed
Time: 1 ms (100%), Space: 56.6 MB (29.23%) - LeetHub
1 parent e21d6c4 commit 6613620

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* Definition for a binary tree node.
10+
* function TreeNode(val, left, right) {
11+
* this.val = (val===undefined ? 0 : val)
12+
* this.left = (left===undefined ? null : left)
13+
* this.right = (right===undefined ? null : right)
14+
* }
15+
*/
16+
/**
17+
* @param {ListNode} head
18+
* @param {TreeNode} root
19+
* @return {boolean}
20+
*/
21+
var isSubPath = function(head, root) {
22+
if (root== null) return false;
23+
return dfs(head, root) || isSubPath(head, root.left) ||isSubPath(head, root.right);
24+
function dfs(head, root) {
25+
if (head === null) return true;
26+
if (root === null) return false;
27+
if (head.val != root.val) return false;
28+
// if (head.val === root.val) {
29+
return dfs(head.next, root.left) ||dfs(head.next, root.right)
30+
// }
31+
}
32+
};

0 commit comments

Comments
 (0)