码迷,mamicode.com
首页 >  
搜索关键字:binary tree    ( 23211个结果
【树】114. 二叉树展开为链表
题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode() : val( ...
分类:其他好文   时间:2020-05-02 15:18:35    阅读次数:53
1143 Lowest Common Ancestor (30分)
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants. A binary search tree (BST) i ...
分类:其他好文   时间:2020-05-02 14:54:12    阅读次数:50
二叉树的实现
# coding:utf8 class Node(): def __init__(self, _item): self.item = _item self.left = None self.right = None class Tree(): def __init__(self): self.roo ...
分类:其他好文   时间:2020-05-02 14:51:38    阅读次数:63
1147 Heaps (30分)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the ...
分类:其他好文   时间:2020-05-02 14:47:58    阅读次数:59
c++ 树状数组
关于树状数组 树状数组,即 Binary Indexed Tree ,主要用于维护查询区间和 属于 log 型数据结构 和线段树比较 都是 log 级别 树状数组常数、耗费的空间都比线段树小 树状数组无法完成复杂的区间操作,功能有限 树状数组介绍 二叉树大家一定不陌生 然而真实的树状数组省去了一些空 ...
分类:编程语言   时间:2020-05-02 13:28:12    阅读次数:71
【树】124. 二叉树中的最大路径和
题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : ...
分类:其他好文   时间:2020-05-02 13:26:05    阅读次数:69
【树】95. 不同的二叉搜索树 II
题目: 给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。 示例: 输入: 3输出:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1,3], [1,null,2,null,3]] 解释:以上的输出对应以下 5 种不同结构 ...
分类:其他好文   时间:2020-05-02 12:18:23    阅读次数:65
LeetCode 144. 二叉树的前序遍历 Binary Tree Postorder Traversal (Medium)
给定一个二叉树,返回它的 前序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 解法一:迭代 解法二:递归 /** * Definition for a binary t ...
分类:其他好文   时间:2020-05-02 11:38:36    阅读次数:52
[LeetCode] 255. Verify Preorder Sequence in Binary Search Tree
验证前序遍历序列二叉搜索树。题意是给一个二叉搜索树的前序遍历的结果,请你验证这个结果是否正确。例子, Consider the following binary search tree: 5 / \ 2 6 / \ 1 3 Example 1: Input: [5,2,6,1,3] Output: ...
分类:其他好文   时间:2020-05-02 09:53:55    阅读次数:58
【设计模式】单例模式
定义 确保某个类只有一个实例 实现方式 饿汉式加载(线程安全) 等价于 懒汉式加载 非线程安全 线程安全 1. Double Check 2. 借助Lazy "示例代码 github" ...
分类:其他好文   时间:2020-05-02 09:27:16    阅读次数:58
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!