原文:leetcode教程系列——Binary Tree

tree是一种常用的数据结构用来模拟真实物理世界里树的层级结构。每个tree有一个根 root 节点和指向其他节点的叶子 leaf 节点。从graph的角度看,tree也可以看作是有N个节点和N 个边的有向无环图。 Binary tree是一个最典型的树结构。顾名思义,二分数的每个节点最多有两个children,分别叫左叶子节点与右叶子节点。下面的内容可以让你学习到: 理解tree的概念以及bi ...

2020-01-07 15:13 0 242 推荐指数:

查看详情

[Leetcode] Balanced Binary Tree

问题:给一个二叉树,写一个算法判断这个树是不是balanced。 Solution #1. 第一次遇到这个问题时我的解法,如下: 写了一个getDepth()函数,访问每个节点都要调用一次这个函数。这个Solution也通过了leetcode的验证程序,但是后来想了想,I ...

Sun May 04 08:58:00 CST 2014 2 6363
LeetCode Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which ...

Sun Oct 28 06:40:00 CST 2012 5 4228
[LeetCode] Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node ...

Fri Nov 16 17:23:00 CST 2012 2 4267
LeetCode:Recover Binary Search Tree

其他LeetCode题目欢迎访问:LeetCode结题报告索引 题目链接 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its ...

Wed Nov 27 22:51:00 CST 2013 2 2874
LeetCode Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 非递归版本: 用一个栈来模拟递归的情况, 首先思考inorder ...

Sun Oct 28 05:48:00 CST 2012 0 3142
[leetcode]Balanced Binary Tree @ Python

原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/ 题意:判断一颗二叉树是否是平衡二叉树。 解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算 ...

Sat May 10 18:54:00 CST 2014 0 5388
[LeetCode] Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest ...

Tue Nov 13 00:53:00 CST 2012 0 3355
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM