Question

Write a function to check whether the given binary tree has the given value node?

Login to Submit

Examples

The first parameter to solve() is the tree and the second parameter is the value to search for. 

Binary tree will be created like this:

let a = {val:1, left:null, right:null};
let b = {val:2, left:null, right:null};
let c = {val:3, left:null, right:null};
let d = {val:4, left:null, right:null};
let e = {val:5, left:null, right:null};

a.left = b;
a.right = c;
b.left = d;
b.right = e;

Since a is the head of the binary tree, the function solve() will be called like this:

solve(a)

For questions asking the modification of the given binary tree, you must return the head of the same tree after the operation asked by the question is complete.