1816. Lowest Common Ancestor of a Binary Tree IV

Medium
Hash Table
Tree
Depth-First Search
Binary Tree

Description

Hints

Hint 1
Starting from the root, traverse the left and the right subtrees, checking if one of the nodes exist there.
Hint 2
If one of the subtrees doesn't contain any given node, the LCA can be the node returned from the other subtree
Hint 3
If both subtrees contain nodes, the LCA node is the current node.

Statistics

Acceptance
79.4%
Submissions
77,782
Accepted
61,782