MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / dfs

Method dfs

LinkedListInBinaryTree.java:2–7  ·  view source on GitHub ↗
(ListNode head, TreeNode node)

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean dfs(ListNode head, TreeNode node){
3 if(head == null) return true;
4 if(node == null) return false;
5 if(head.val != node.val) return false;
6 return dfs( head.next, node.left) || dfs( head.next, node.right);
7 }
8 public boolean isSubPath(ListNode head, TreeNode root) {
9 if(root == null) return false;
10 if(root.val == head.val){

Callers 1

isSubPathMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected