函数功能: 1、如果p q都存在,返回他们的公共祖先 2、只存在一个,那就返回存在的一个 3、都不存在,返回NULL 递归左右子树,左子树的结果为left1,右子树结果为right1 left1空代表结果(公共祖先)在right1,反之亦然。 如果都非空,说明p q在左右两边,此时要返回根结点。 否 ...
分类:
其他好文 时间:
2020-03-03 11:14:42
阅读次数:
71
集合的大小不会超过三 #include<bits/stdc++.h> #define forn(i, n) for (int i = 0 ; i < int(n) ; i++) #define fore(i, s, t) for (int i = s ; i < (int)t ; i++) #def ...
分类:
其他好文 时间:
2020-03-02 21:02:54
阅读次数:
97
1. 题目 2. 思路 1. 如下图 发现规律,对于最左边来说,后面所有的集合都是先小后大或者先大后小,如果小大交错那么不符合 2. 使用1中规律确定是否为镜像,结合二叉排序树的特点,用递归建立树 3. 输出树的后序遍历 3. 注意点 1. 发现规律比较困难 2. 树的题目一般都要用递归 4. 代码 ...
分类:
其他好文 时间:
2020-03-02 01:00:34
阅读次数:
54
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, ...
分类:
其他好文 时间:
2020-03-01 12:41:23
阅读次数:
61
摘要:上一篇广告中那些趣事系列1:广告统一兴趣建模流程,我们了解了如何为广告主圈人群以及如何刻画用户的兴趣度。要想给用户打标签,我们需要构建数据源和标签的关联,也就是item-tag。针对数量较少的app数据源我们可以使用人工打标的方式来识别,但是对于news、用户query等数量较多的数据源则需要... ...
分类:
其他好文 时间:
2020-03-01 12:39:38
阅读次数:
63
108. Convert Sorted Array to Binary Search Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this ...
分类:
编程语言 时间:
2020-02-29 22:03:51
阅读次数:
78
思路 树链剖分求出LCA 用LCA求两点之间距离(借助到根的距离):depth[x] + depth[y] 2 depth[LCA]; 加边后a,b两点可以保持距离为k的条件: k =改变后的距离; 改变后的距离刚好等于k,如果不等那么距离相差偶数,来回走来走去就能走到走凑成k 考虑加边对a,b距离 ...
分类:
其他好文 时间:
2020-02-29 20:56:01
阅读次数:
70
114 Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in place. 将二叉树展开成链表 [![]D:\dataStructure\Leetcode\114.png] (D: ...
分类:
编程语言 时间:
2020-02-29 12:58:17
阅读次数:
60
面试题32 - I. 从上到下打印二叉树 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x ...
分类:
其他好文 时间:
2020-02-28 22:34:33
阅读次数:
45
题目: Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to ...
分类:
编程语言 时间:
2020-02-28 14:11:20
阅读次数:
84