Hello I was wondering if someone could help walk me through what happens when I have a couple of recursive calls involving a boolean operator? So for example how would this code run?
boolean covers(TreeNode root, TreeNode p) {
if(root == null) return false;
if(root == p) return true;
return covers(root.left, p) || covers(root.right, p); //this is what confuses me
}
For context TreeNode root is the root of the Btree and TreeNode p is a node in the Btree.
null, it will executecovers(root.left,p), then based on the result, as you have||, will executecovers(root.right,p)if needed . As the walkthrough, use a debugger or add some log to follow the code.return covers(root.left, p) || covers(root.right, p);will return true if either of the statements are true