Lowest Common Ancestor Of A Binary Tree
1. Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 2. According to the definition of LCA on Wikipedia: The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself). 3. If LCA does not exist in the tree print null.
1. The number of nodes in the tree is in the range [-1000, 1000]. 2. -109 <= Node.val <= 109 All Node.val are unique. p != q p and q may or may not exist in the tree.
Input is managed for you.
Output is managed for you.
10 5 3 13 null null -2 null null 2 null 1 null null -3 null 11 null null 13 3