码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果)
[Leetcode] Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Hide TagsDepth-first SearchLinked List方法一...
分类:其他好文   时间:2015-04-09 16:50:31    阅读次数:144
Balanced Binary Tree
判断一棵二叉树是否是平衡树 看到二叉树的题目,基本都可以用递归的思想求解。对于判断是否是一棵平衡树可分为以下几个步骤: 计算左子树和右子树的高度差是否大于1,是则返回false 判断左子树是否是平衡树,判断右子树是否是平衡树 class Solution {public: bool isBalanc...
分类:其他好文   时间:2015-04-09 15:18:20    阅读次数:100
Leetcode: Convert Sorted Array to Binary Search Tree
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析: 将已经排序好的数组转成高度平衡的二叉排序树。 依旧二分法。C++参考代码:/** * Definition for binary tree * struct TreeNode {...
分类:其他好文   时间:2015-04-09 13:51:49    阅读次数:112
173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next...
分类:其他好文   时间:2015-04-09 13:33:52    阅读次数:106
LeetCode --- 94. Binary Tree Inorder Traversal
题目链接:Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return ...
分类:其他好文   时间:2015-04-09 12:00:06    阅读次数:223
LeetCode --- 95. Unique Binary Search Trees II
题目链接:Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique B...
分类:其他好文   时间:2015-04-09 11:59:05    阅读次数:171
Binary Tree Maximum Path Sum--LeetCode
题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / 2 3 思路:刚开始思路...
分类:其他好文   时间:2015-04-09 11:52:49    阅读次数:107
Sum Root to Leaf Numbers--LeetCode
题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Fi...
分类:其他好文   时间:2015-04-09 11:51:56    阅读次数:161
Flatten Binary Tree to Linked List--LeetCode
题目: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / 2 5 / \ 3 4 6 The flattened tree should look like: ...
分类:其他好文   时间:2015-04-09 10:38:07    阅读次数:128
【leetcode】Binary Tree Inorder Traversal
与前面的先序遍历相似。此题为后序遍历。C++: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *rig...
分类:其他好文   时间:2015-04-08 23:23:14    阅读次数:159
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!