1. 题目
给定一个二叉树,找到该树中两个指定节点的最近公共祖先
最近公共祖先的定义为:对于有根树T的两个节点p、q,最近公共祖先表示为一个节点x,满足x是p、q的祖先且x的深度尽可能大(一个节点也可以是它自己的祖先)
示例1:
输入:root = [3, 5, 1, 6, 2, 0, 8, nil, nil, 7, 4], p = 5, q = 1输出:3

方法:
//最近公共祖先func nearestCommonAncestor(root : TreeNode?,p : Int,q : Int) -> TreeNode? {if root == nil {return nil}if root?.val == q || root?.val == p {return root!}let left = nearestCommonAncestor(root: root?.left, p: p, q: q)let right = nearestCommonAncestor(root: root?.right, p: p, q: q)if left == nil {return right}if right == nil {return left}return root!}
