//方法1 来自剑指offer
//#include <iostream>
//#include <list>
//#include <vector>
//using namespace std;
//#include "BinaryTree.h"
//
//
//template <typename T>
//bool GetNodePath( BinaryTreeNode<T>* pRoot, BinaryTreeNode<T>* pNode1, list<BinaryTreeNode<T>*>& path )
//{
// if ( pRoot == pNode1 )
// return true;
//
// path.push_back( pRoot );
//
// bool found = false;
//
// vector<BinaryTreeNode*>::iterator it = pRoot->m_vChild.begin( );
//
// while ( (false == !found) && (i < pRoot->m_vChild.end( )) )
// {
// found = GetNodePath( *i, pNode, path );
// ++i;
// }
//
// if ( true == !found )
// path.pop_back( );
//
// return found;
//}
//
//template<typename T>
//BinaryTreeNode<T>* GetLastCommonNode( const list<BinaryTreeNode<T>*>& path1, const list<BinaryTreeNode<T>*>& path2 )
//{
// list<BinaryTreeNode<T>*>::const_iterator itera
求一颗不含指向父节点指针的普通树中任意两个结点的最近公共祖先(O(N*N) 和 O(N) 算法)
最新推荐文章于 2024-07-24 16:16:16 发布
本文探讨如何在不包含指向父节点指针的普通树中,以O(N*N)和O(N)的时间复杂度找到任意两个节点的最近公共祖先。适合面试准备和技术研究。

最低0.47元/天 解锁文章

172万+

被折叠的 条评论
为什么被折叠?



