二叉树
文章平均质量分 80
哎-哭泣的鱼
这个作者很懒,什么都没留下…
展开
-
【九度】题目1509:树中两个结点的最低公共祖先
题目描述:给定一棵树,同时给出树中的两个结点,求它们的最低公共祖先。输入:输入可能包含多个测试样例。对于每个测试案例,输入的第一行为一个数n(0其中每个测试样例包括两行,第一行为一个二叉树的先序遍历序列,其中左右子树若为空则用0代替,其中二叉树的结点个数node_num第二行为树中的两个结点的值m1与m2(0输出:对应每个原创 2013-12-16 17:44:21 · 1080 阅读 · 0 评论 -
【LeetCode】Binary Tree Postorder Traversal 二叉树后序遍历递归以及非递归算法
Binary Tree Postorder Traversal Total Accepted: 15614 Total Submissions: 50928 My SubmissionsGiven a binary tree, return the postorder traversal of its nodes' values.For example:Given binary t原创 2014-05-07 18:31:28 · 1387 阅读 · 0 评论 -
【LeetCode】Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal II Total Accepted: 4229 Total Submissions: 13624 My SubmissionsGiven a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left原创 2014-01-12 22:27:41 · 896 阅读 · 0 评论 -
【LeetCode】Recover Binary Search Tree
Recover Binary Search Tree Total Accepted: 7163 Total Submissions: 31922 My SubmissionsTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its str原创 2014-04-10 12:19:53 · 1170 阅读 · 0 评论 -
【LeetCode】Binary Tree Level Order Traversal
Binary Tree Level Order Traversal Total Accepted: 5091 Total Submissions: 16977 My SubmissionsGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, lev原创 2014-01-10 13:26:34 · 958 阅读 · 0 评论 -
【九度】题目1044:Pre-Post
题目1044:Pre-Post时间限制:1 秒内存限制:32 兆特殊判题:否提交:502解决:291题目描述: We are all familiar with pre-order, in-order and post-order traversals of binary trees. A common problem in data structure classes is t原创 2014-03-20 18:11:33 · 2836 阅读 · 0 评论 -
【LeetCode】Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Search Tree
1、Convert Sorted Array to Binary Search Tree Total Accepted: 8749 Total Submissions: 27493 My SubmissionsGiven an array where elements are sorted in ascending order, convert it to a height balance原创 2014-03-16 13:24:18 · 935 阅读 · 0 评论 -
【LeetCode】Maximum Depth of Binary Tree && Minimum Depth of Binary Tree
1、Maximum Depth of Binary TreeTotal Accepted: 10889 Total Submissions: 24617 My SubmissionsGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest原创 2014-02-26 11:09:35 · 807 阅读 · 0 评论 -
【LeetCode】236 Lowest Common Ancestor of a Binary Tree
Lowest Common Ancestor of a Binary TreeTotal Accepted: 1207 Total Submissions: 4143 My Submissions Question Solution Given a binary tree, find the lowest common ancestor (LCA) of two given nodes i原创 2015-07-13 17:51:14 · 1588 阅读 · 0 评论 -
【LeetCode】Sum Root to Leaf Numbers
Sum Root to Leaf Numbers Total Accepted: 4893 Total Submissions: 17365 My SubmissionsGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example原创 2014-01-08 00:02:59 · 728 阅读 · 0 评论 -
【LeetCode】Path Sum II
Path Sum II Total Accepted: 4441 Total Submissions: 16502 My SubmissionsGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given th原创 2014-01-08 15:42:41 · 1364 阅读 · 0 评论 -
【LeetCode】Populating Next Right Pointers in Each Node I & II
Populating Next Right Pointers in Each Node Total Accepted: 6122 Total Submissions: 17900 My SubmissionsGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode原创 2014-01-16 13:24:35 · 962 阅读 · 0 评论 -
【九度】题目1523:从上往下打印二叉树
题目描述:从上往下打印出二叉树的每个节点,同层节点从左至右打印。输入:输入可能包含多个测试样例,输入以EOF结束。对于每个测试案例,输入的第一行一个整数n(1Ci=’d’表示第i个节点有两子孩子,紧接着是左孩子编号和右孩子编号。Ci=’l’表示第i个节点有一个左孩子,紧接着是左孩子的编号。Ci=’r’表示第i个节点有一个右孩子,紧接着是右孩子的编号。Ci=’z’表示原创 2014-01-10 14:04:52 · 854 阅读 · 0 评论 -
【LeetCode】Binary Tree Preorder Traversal 二叉树前序遍历递归以及非递归算法
Binary Tree Preorder Traversal Total Accepted: 17403 Total Submissions: 50093 My SubmissionsGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tre原创 2014-05-07 17:14:12 · 782 阅读 · 0 评论 -
【LeetCode】Path Sum
Path Sum Total Accepted: 5082 Total Submissions: 17224 My SubmissionsGiven 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 eq原创 2014-01-08 14:10:19 · 1054 阅读 · 0 评论 -
【LeetCode】Binary Tree Inorder Traversal 二叉树中序遍历递归以及非递归算法
Binary Tree Inorder Traversal Total Accepted: 16494 Total Submissions: 47494Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3},原创 2014-05-07 18:21:16 · 1327 阅读 · 0 评论 -
【九度】题目1521:二叉树的镜像
题目1521:二叉树的镜像时间限制:1 秒内存限制:128 兆特殊判题:否提交:1026解决:265题目描述:输入一个二叉树,输出其镜像。输入:输入可能包含多个测试样例,输入以EOF结束。对于每个测试案例,输入的第一行为一个整数n(0Ci=’d’表示第i个节点有两子孩子,紧接着是左孩子编号和右孩子编号。Ci=’l’表示第i个节点有一个左孩子,紧接着是左孩子的编号原创 2014-05-07 14:53:18 · 790 阅读 · 0 评论 -
【LeetCode】Balanced Binary Tree
Balanced Binary Tree Total Accepted: 10515 Total Submissions: 33226 My SubmissionsGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defin原创 2014-03-24 16:41:31 · 731 阅读 · 0 评论 -
【LeetCode】Symmetric Tree
Symmetric Tree Total Accepted: 8236 Total Submissions: 25682 My SubmissionsGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tr原创 2014-02-12 13:12:45 · 770 阅读 · 0 评论 -
【LeetCode】Same Tree
Same Tree Total Accepted: 8888 Total Submissions: 20908 My SubmissionsGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are s原创 2014-02-10 13:48:04 · 1215 阅读 · 0 评论 -
【LeetCode】235 Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search TreeTotal Accepted: 3808 Total Submissions: 9820 My Submissions Question Solution Given a binary search tree (BST), find the lowest common ancestor (LCA)原创 2015-07-13 17:39:13 · 1106 阅读 · 0 评论