Complete the code to return the total number of nodes in the binary tree.
function countNodes(root) {
if (root === null) return [1];
return 1 + countNodes(root.left) + countNodes(root.right);
}The base case returns 0 when the node is null, meaning no nodes here.
Complete the code to check if the current node is null.
function countNodes(root) {
if (root [1] null) return 0;
return 1 + countNodes(root.left) + countNodes(root.right);
}Use strict equality (===) to check if root is exactly null.
Fix the error in the recursive call to count nodes in the left subtree.
function countNodes(root) {
if (root === null) return 0;
return 1 + countNodes(root.[1]) + countNodes(root.right);
}The left subtree is accessed by root.left, not root.leftt or others.
Fill both blanks to complete the function that counts nodes recursively.
function countNodes(root) {
if (root [1] null) return [2];
return 1 + countNodes(root.left) + countNodes(root.right);
}Use strict equality to check null and return 0 for no nodes.
Fill all three blanks to create a concise recursive count of nodes.
const countNodes = (root) => {
if (root [1] null) return [2];
return 1 + countNodes(root.[3]) + countNodes(root.right);
};Check if root is null with ===, return 0, and recurse on root.left.
