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

Method travel

TreePathToGivenNode.java:8–20  ·  view source on GitHub ↗
(TreeNode root, int B,ArrayList<Integer> list)

Source from the content-addressed store, hash-verified

6 return list;
7 }
8 public static boolean travel(TreeNode root, int B,ArrayList<Integer> list)
9 {
10 if(root==null) return false;
11
12 list.add(root.val);
13
14 if(root.val==B) return true;
15
16 if(travel(root.left,B,list) || travel(root.right,B,list))
17 return true;
18 list.remove(list.size()-1);
19 return false;
20 }
21}

Callers 1

solveMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected