随笔分类 - 树
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example,
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example,
阅读全文
摘要: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 l
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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 symmet
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Example 2: Follow up: A
阅读全文
摘要: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
阅读全文
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: 题意 给定一数n,求1-n所组成的所有可能的BST树的集合 题解
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: 1 class Solution { 2 public: 3 void build(TreeNode*root, vector<int>&
阅读全文
摘要:描述 Given a connected undirected graph, tell if its minimum spanning tree is unique.Definition 1 (Spanning Tree): Consider a connected, undirected grap
阅读全文
摘要:二叉树的深度(10分) 题目内容: 给定一棵二叉树,求该二叉树的深度 二叉树深度定义:从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的节点个数为树的深度 输入格式: 第一行是一个整数n,表示二叉树的结点个数。二叉树结点编号从1到n,根结点为1,n <= 10 接下来有n行,
阅读全文
摘要:题目内容: 我们知道如何按照三种深度优先次序来周游一棵二叉树,来得到中根序列、前根序列和后根序列。反过来,如果给定二叉树的中根序列和后根序列,或者给定中根序列和前根序列,可以重建一二叉树。本题输入一棵二叉树的中根序列和后根序列,要求在内存中重建二叉树,最后输出这棵二叉树的前根序列。 用不同的整数来唯
阅读全文
摘要:描述 Biologists finally invent techniques of repairing DNA that contains segments causing kinds of inherited diseases. For the sake of simplicity, a DNA
阅读全文
摘要:描述 有若干种病毒,每种病毒的特征代码都是一个01串。 每个程序也都是一个01串。 问是否存在不被病毒感染(不包含任何病毒的特征代码)的无限长的程序。 输入第一行是整数n,表示有n个病毒接下来n行,每行是一个由 0,1构成的字符串,表示一个病毒特征代码所有的病毒的特征代码总长度不超过30000输出如
阅读全文
摘要:描述 Aliens on planet Pandora also write computer programs like us. Their programs only consist of capital letters (‘A’ to ‘Z’) which they learned from
阅读全文
摘要:描述 给若干个模式串,以及若干个句子,判断每个句子里是否包含模式串。 句子和模式串都由小写字母组成 输入第一行是整数n,表示有n个模式串 ( n <= 1000)接下来n行每行一个模式串。每个模式串长度不超过20接下来一行是整数m,表示有m个句子 (m <= 1000)接下来m行,每行一个句子,每个
阅读全文
摘要:题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N、M,分别表示该数列数字的个数和操作的总个数。 第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。 接下来M行每行包含3或
阅读全文
摘要:描述 The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all
阅读全文
摘要:描述 N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering h
阅读全文