Lowest Common Ancestor of a Binary Tree LeetCode solution in JavaScript

1
var lowestCommonAncestor = function (root, p, q) {
2
if (!root || root.val == p.val || root.val == q.val) return root;
3

4
let left = lowestCommonAncestor(root.left, p, q);
5
let right = lowestCommonAncestor(root.right, p, q);
6

7
return left && right ? root : left || right;
8
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0