
树
码不停Ti
信息安全在校大学生
展开
-
【LeetCode】337. 打家劫舍 III
在上次打劫完一条街道之后和一圈房屋后,小偷又发现了一个新的可行窃的地区。这个地区只有一个入口,我们称之为“根”。 除了“根”之外,每栋房子有且只有一个“父“房子与之相连。一番侦察之后,聪明的小偷意识到“这个地方的所有房屋的排列类似于一棵二叉树”。 如果两个直接相连的房子在同一天晚上被打劫,房屋将自动报警。计算在不触动警报的情况下,小偷一晚能够盗取的最高金额。示例 1:输入: [3,2,...原创 2020-01-18 11:54:14 · 649 阅读 · 0 评论 -
【LeetCode】102. 二叉树的层次遍历
给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。例如:给定二叉树:[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层次遍历结果:[ [3], [9,20], [15,7]]来源:力扣(LeetCode)链接:https://leetcode-cn...原创 2020-01-11 13:03:54 · 381 阅读 · 0 评论 -
【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree 公共祖先
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between ...原创 2019-12-12 22:04:30 · 349 阅读 · 0 评论 -
【LeetCode】437. Path Sum III树
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it mus...原创 2019-12-11 20:42:10 · 390 阅读 · 0 评论 -
4-15 根据后序和中序遍历输出先序遍历 (15 分)
4-15根据后序和中序遍历输出先序遍历(15分)本题要求根据给定的一棵二叉树的后序遍历和中序遍历结果,输出该树的先序遍历结果。输入格式:第一行给出正整数N(≤30),是树中结点的个数。随后两行,每行给出N个整数,分别对应后序遍历和中序遍历结果,数字间以空格分隔。题目保证输入正确对应一棵二叉树。输出格式:在一行中输出Preorder:以及该树的先序遍历结果。数字间有1个空格...原创 2019-10-23 20:43:35 · 1050 阅读 · 0 评论 -
4-14 还原二叉树 (15 分)
4-14还原二叉树(15分)给定一棵二叉树的先序遍历序列和中序遍历序列,要求计算该二叉树的高度。输入格式:输入首先给出正整数N(≤50),为树中结点总数。下面两行先后给出先序和中序遍历序列,均是长度为N的不包含重复英文字母(区别大小写)的字符串。输出格式:输出为一个整数,即该二叉树的高度。输入样例:9ABDFGHIECFDHGIBEAC输出样例:...原创 2019-10-23 18:30:45 · 1401 阅读 · 0 评论 -
4-11 Isomorphic (10 分)
4-11Isomorphic(10分)Two trees,T1andT2, areisomorphicifT1can be transformed intoT2by swapping left and right children of (some of the) nodes inT1. For instance, the two trees in Figure 1 ...原创 2019-10-23 13:26:03 · 1570 阅读 · 0 评论 -
4-13 先序输出叶结点 (10 分)
4-13先序输出叶结点(10分)本题要求按照先序遍历的顺序输出给定二叉树的叶结点。函数接口定义:void PreorderPrintLeaves( BinTree BT );其中BinTree结构定义如下:typedef struct TNode *Position;typedef Position BinTree;struct TNode{ Eleme...原创 2019-10-23 12:39:29 · 7350 阅读 · 0 评论 -
4-12 求二叉树高度 (10 分)
4-12求二叉树高度(10分)本题要求给定二叉树的高度。函数接口定义:int GetHeight( BinTree BT );其中BinTree结构定义如下:typedef struct TNode *Position;typedef Position BinTree;struct TNode{ ElementType Data; BinTree...原创 2019-10-23 12:36:37 · 6193 阅读 · 0 评论 -
【HBU】数据结构树练习题
4-1某二叉树的前序和后序遍历序列正好相反,则该二叉树一定是(4分)空或只有一个结点 高度等于其结点数 任一结点无左孩子 任一结点无右孩子作者: DS课程组单位: 浙江大学4-2已知一棵二叉树的先序遍历结果是ABC,则以下哪个序列是不可能的中序遍历结果:(4分)ABC BAC CBA CAB作者: DS课程组单位: 浙江大学4-3...原创 2019-10-15 14:23:48 · 46252 阅读 · 5 评论 -
【LeetCode】617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree...原创 2019-10-05 23:29:57 · 398 阅读 · 0 评论 -
【LeetCode】104. Maximum Depth of Binary Tree
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.Note:A leaf is a node with no childre...原创 2019-10-04 20:21:30 · 334 阅读 · 0 评论