摘要:从root开始遍历,如果n1和n2中的任一个和root匹配,那么root就是LCA。 如果都不匹配,则分别递归左、右子树,如果有一个 key(n1或n2)出现在左子树,并且另一个key(n1或n2)出现在右子树,则root就是LCA. 如果两个key都出现在左子树,则说明LCA在左子树中,否则在右子...
阅读全文
01 2016 档案
摘要:从root开始遍历,如果n1和n2中的任一个和root匹配,那么root就是LCA。 如果都不匹配,则分别递归左、右子树,如果有一个 key(n1或n2)出现在左子树,并且另一个key(n1或n2)出现在右子树,则root就是LCA. 如果两个key都出现在左子树,则说明LCA在左子树中,否则在右子...
阅读全文
摘要:解决二叉树的很多问题的方案都是基于对二叉树的遍历。遍历二叉树的前序,中序,后序三大方法算是计算机科班学生必写代码了。其递归遍历是人人都能信手拈来,可是在手生时写出非递归遍历恐非易事。正因为并非易事,所以网上出现无数的介绍二叉树非递归遍历方法的文章。可是大家需要的真是那些非递归遍历代码和讲述吗?代码早...
阅读全文
摘要:#include "List.h"#include #include using namespace std;#define max(a, b) (a) > (b) ? (a) : (b)// LeetCode, Longest Substring Without Repeating Charact...
阅读全文
摘要:// TwoNum.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;//Definition for singly...
阅读全文
摘要:#ifndef List_h__#define List_h__#include struct ListNode{ int value; ListNode* pNext; ListNode(int n) :value(n), pNext(nullptr){}};class List...
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
阅读全文
摘要:先看下面代码:#include #include #include class Test{public: Test(int i) :a(i) { } ~Test() { }public: void Print() { pri...
阅读全文
|