package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
type TreeNode = structures.TreeNode
func lowestCommonAncestor236(root, p, q *TreeNode) *TreeNode {
if root == nil || root == q || root == p {
return root
}
left := lowestCommonAncestor236(root.Left, p, q)
right := lowestCommonAncestor236(root.Right, p, q)
if left != nil {
if right != nil {
return root
}
return left
}
return right
}