二叉树
iyangdi
这个作者很懒,什么都没留下…
展开
-
Google算法题:二叉树的最大深度
题目 题目来源:Link LintCode链接 给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的距离。 您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵如下的二叉树: 1 / \ 2 3 / \ 4 5 这个二叉树的最大深度为3 代原创 2017-08-07 19:58:48 · 231 阅读 · 0 评论 -
LintCode:M-最近祖先
LinCode链接 给定一棵二叉树,找到两个节点的最近公共父节点(LCA)。 最近公共祖先是两个节点的公共的祖先节点且具有最大深度。 注意事项 假设给出的两个节点都在树中存在 您在真实的面试中是否遇到过这个题? Yes 样例 对于下面这棵二叉树 4 / \ 3 7 / \ 5原创 2017-08-29 09:24:31 · 285 阅读 · 0 评论 -
LintCode:M-二叉树的锯齿形遍历
LintCode链接 给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行) 您在真实的面试中是否遇到过这个题? Yes 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回其锯齿形的层次遍历为:原创 2017-08-30 11:37:18 · 235 阅读 · 0 评论 -
LintCode:M-抢劫房屋|||
LintCode链接 在上次打劫完一条街道之后和一圈房屋之后,窃贼又发现了一个新的可以打劫的地方,但这次所有的房子组成的区域比较奇怪,聪明的窃贼考察地形之后,发现这次的地形是一颗二叉树。与前两次偷窃相似的是每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且当相邻的两个房子同一天被打劫时,该系统会自动报警。 算一算,如果今晚去打劫,你最多可以得到多原创 2017-08-30 13:06:15 · 369 阅读 · 0 评论 -
LeetCode:M-105. Construct Binary Tree from Preorder and Inorder Traversal
LeetCode链接 Given preorder and inorder traversal of a tree, construct the binary tree. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left;原创 2017-09-25 22:44:30 · 376 阅读 · 0 评论 -
LeetCode:M-236. Lowest Common Ancestor of a Binary Tree
LeetCode链接 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is define原创 2017-09-11 11:22:00 · 168 阅读 · 0 评论