码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果
1127 ZigZagging on a Tree (30分)
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and ino ...
分类:其他好文   时间:2020-05-06 13:56:18    阅读次数:55
【LeetCode-树】二叉搜索树中第K小的元素
题目描述 给定一个二叉搜索树,编写一个函数?kthSmallest?来查找其中第?k?个最小的元素。 说明: 你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数。 示例: 题目链接: https://leetcode cn.com/problems/kth smallest elemen ...
分类:其他好文   时间:2020-05-06 12:02:09    阅读次数:46
99. 恢复二叉搜索树
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), ...
分类:其他好文   时间:2020-05-06 11:59:27    阅读次数:66
96. 不同的二叉搜索树
二叉查找树(Binary Search Tree),(又:二叉搜索树,二叉排序树)它或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉排序树。 思路: ...
分类:其他好文   时间:2020-05-05 11:11:57    阅读次数:65
LeetCode 98
https://leetcode-cn.com/problems/validate-binary-search-tree/ 树题,没什么好说的,直接递归就完事了。 第一种,使用中序遍历将输出值保存在list中,然后检查这个list是否升序的就可以AC.不过这个方法比较慢,3ms,java上只击败了1 ...
分类:其他好文   时间:2020-05-05 11:01:33    阅读次数:48
95. 不同的二叉搜索树 II
用递归即可 因为是二叉搜索树,也就是根大于左子节点,根小于右子节点,这就好办了,对于每个可能的根节点,求出所有左右子树的集合,双循环配对 /** * Definition for a binary tree node. * public class TreeNode { * int val; * T ...
分类:其他好文   时间:2020-05-05 10:57:51    阅读次数:61
六、二叉树和红黑树
一、二叉查找/搜索/排序树BST (binary search/sort tree) 或者是一棵空树; 或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根节点的值; 若它的右子树上所有结点的值均大于它的根节点的值; 它的左、右子树也分别为二叉排序树。 二、平衡二叉树( ...
分类:其他好文   时间:2020-05-04 21:26:00    阅读次数:67
LeetCode 110. 平衡二叉树 Balanced Binary Tree (Easy)
给定一个二叉树,判断它是否是高度平衡的二叉树。 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1。 来源:力扣(LeetCode) 解法一:记录树高度 /** * Definition for a binary tree node. * struct T ...
分类:其他好文   时间:2020-05-04 17:24:08    阅读次数:52
94-二叉树中序遍历
思路:中序遍历,就是按照“左,中,右”的顺序遍历一个二叉树。 1.递归,先递归左子树,之后把根节点放进res里,在递归右节点即可,可以把res设置为全局变量,或者再写一个函数,res当成参数传递都可以。代码如下,比较简单。 /** * Definition for a binary tree nod ...
分类:其他好文   时间:2020-05-04 15:51:55    阅读次数:61
LeetCode - Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a complete binary tree every le ...
分类:其他好文   时间:2020-05-04 15:47:22    阅读次数:55
12390条   上一页 1 ... 47 48 49 50 51 ... 1239 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!