boolean dfs(TreeNode root, int target) {
if (root == null)
return false;
if (root.data == target)
return true;
return dfs(root.left, target) || dfs(root.right, target);
}
What is the program actually doing in the last line...can anyone please explain.?
targetis found in left sub-tree due to||short circuiting.targetin the left sub-tree, then you don't need to explore the right sub-tree. So that||short-circuit is in fact good.