二叉树
SYSU_xiandan
Life is like a dream.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
104. Maximum Depth of Binary Tree
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 题意是求二叉树的最大深度。有两种方法,第原创 2017-09-25 08:45:31 · 231 阅读 · 0 评论 -
116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node.原创 2017-11-22 15:37:16 · 209 阅读 · 0 评论 -
105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 由题意得,这题是给出一个二叉树的前序和中序序列,然后要求构造这样的一个二叉树。用递归的方法比较容易懂和好写,所原创 2017-11-23 11:07:27 · 185 阅读 · 0 评论 -
106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 题意是给出二叉树的中序和后序,然后构造这个二叉树,这题和105基本是一样的思想和框架,就是区间不太一原创 2017-11-23 12:24:00 · 196 阅读 · 0 评论 -
112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum原创 2017-12-04 09:29:20 · 185 阅读 · 0 评论 -
96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2017-11-26 16:21:20 · 216 阅读 · 0 评论 -
113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \原创 2017-12-05 19:29:07 · 222 阅读 · 0 评论 -
124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The原创 2017-12-06 10:34:38 · 184 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers
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. Find the tota原创 2017-12-06 15:59:32 · 159 阅读 · 0 评论 -
95. Unique Binary Search Trees II
Given an integer 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 BST's shown below. 1原创 2017-11-27 16:44:47 · 272 阅读 · 0 评论 -
109. 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. For this problem, a height-balanced binary tree is defined as a binary tree in which th原创 2017-12-01 11:08:09 · 194 阅读 · 0 评论 -
110. 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 the depth of the two subtrees of every node never diffe原创 2017-11-21 16:23:30 · 203 阅读 · 0 评论 -
145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. 题意是要求二叉树的后序遍历,那原创 2017-11-15 20:45:28 · 208 阅读 · 0 评论 -
数据结构之:二叉树
今天复习到了二叉树,首先是了解一下二叉树的一下定义: 二叉树是每个节点最多有两个子树的树结构,通常称为左/右子树。如图所示: 其中深度Depth可以理解为层数,那么第i层则有2^(i-1)那么多的节点。其中没有左右子树的节点称为叶节点,而 其他的称为根节点。例如值为8~15的节点就是叶子节点。 而树的类型也有很多种,其中基本的有: 1.完全二叉树——假如一棵树的最大深度为D,那么1到原创 2017-10-18 18:50:51 · 459 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20原创 2017-11-17 11:30:01 · 203 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,15,原创 2017-11-17 16:50:00 · 190 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary原创 2017-11-17 17:25:36 · 208 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. 题意是对二叉树进行中序遍历,原创 2017-11-15 19:07:20 · 224 阅读 · 0 评论 -
100. Same Tree
Problem: Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2017-09-11 16:26:54 · 226 阅读 · 0 评论 -
101. Symmetric Tree
Problem: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \原创 2017-09-11 16:59:47 · 273 阅读 · 0 评论 -
144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. 题意是要先序遍历一个二叉树原创 2017-11-14 19:56:00 · 283 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 由题意得,给出一个递增的序列,然后求出它的高度平衡的二叉搜索树。题目比较简单,就用二分法,每次取序列的一半来作为子树的根的结点值,用递归的方法就可以实现,代码如下。 Code(LeetCo原创 2017-11-29 09:39:58 · 212 阅读 · 0 评论 -
98. 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 contains only nodes with keys less than the node's key.Th原创 2017-11-27 17:19:41 · 212 阅读 · 0 评论
分享