Lowest Common Ancestor of a Binary Tree LeetCode solution in JavaScript
1var lowestCommonAncestor = function (root, p, q) {2if (!root || root.val == p.val || root.val == q.val) return root;34let left = lowestCommonAncestor(root.left, p, q);5let right = lowestCommonAncestor(root.right, p, q);67return left && right ? root : left || right;8};