求两节点的最近公共祖先

Node* findlca(Node* root, Node* l, Node *r) {
	if(root == NULL) 
		return root;
	if(root == l || root == r) 
		return root;
	Node *left = findlca(root->left,l,r);
	Node *right = findlca(root->right,l,r);
	if(left && right)
		return root;
	return left ? left : right;
}
posted @ 2019-04-26 09:45  Draymonder  阅读(119)  评论(0编辑  收藏  举报