Complete the code to check if the current node is NULL.
if (root [1] NULL) return NULL;
The base case checks if the current node is NULL using '=='.
Complete the code to check if the current node matches either target node p or q.
if (root == [1] || root == [2]) return root;
We check if the current node is equal to p or q to return it immediately.
Fix the error in the recursive call to search the left subtree.
struct TreeNode* left = [1](root->left, p, q);The function calls itself recursively using its own name 'lowestCommonAncestor'.
Fill both blanks to return the correct ancestor based on left and right subtree results.
if (left != NULL && right != NULL) return [1]; return [2] != NULL ? [2] : right;
If both left and right are not NULL, root is the ancestor. Otherwise, return the non-NULL child.
Fill all three blanks to complete the function signature and return type.
[1] [2] [3](struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) { if (root == NULL) return NULL; if (root == p || root == q) return root; struct TreeNode* left = lowestCommonAncestor(root->left, p, q); struct TreeNode* right = lowestCommonAncestor(root->right, p, q); if (left != NULL && right != NULL) return root; return left != NULL ? left : right; }
The function returns a pointer to a TreeNode, so the signature is 'struct TreeNode* lowestCommonAncestor(...)'.
