![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
树
JohnWill_
小白一个,慢慢成长....
展开
-
二叉树的最小深度
题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 求由根节点至最近的叶节点的路径上的结点总数。注意,...原创 2018-03-17 20:22:15 · 98 阅读 · 0 评论 -
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,#,#,15,7}, 3 / \ 9 20 /...原创 2018-03-27 22:47:01 · 260 阅读 · 0 评论 -
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 bin...原创 2018-03-28 16:03:25 · 79 阅读 · 0 评论 -
maximum-depth-of-a-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.实现代码: * Definition for binary tr...原创 2018-03-28 16:35:29 · 115 阅读 · 0 评论 -
利用先序遍历和中序遍历构造还原二叉树
题目描述Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 题解: 1 / \ 2 3 / \ / \ ...原创 2018-03-28 20:50:14 · 333 阅读 · 0 评论 -
利用中序和后序遍历还原二叉树
题目描述Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 实现代码: /** * Definition for binary tree * str...原创 2018-03-28 21:29:29 · 1003 阅读 · 0 评论 -
binary-tree-level-order-traversal 2
题目描述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,#,#,15,7...原创 2018-03-28 21:56:19 · 123 阅读 · 0 评论 -
判断对称树
题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3 But the follo...原创 2018-03-28 22:49:14 · 190 阅读 · 0 评论 -
判断两棵二叉树相同(递归)
题目描述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.首先,比较两棵树的...原创 2018-03-29 10:04:36 · 2979 阅读 · 0 评论 -
复原二叉搜索树
题目描述Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n ) space is pretty straight forward. Could you devi...原创 2018-03-29 10:16:32 · 204 阅读 · 0 评论 -
二叉搜索树的判定
题目描述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 nod...原创 2018-03-29 14:13:08 · 209 阅读 · 0 评论 -
Unique Binary Search Tree
题目描述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 ...原创 2018-03-29 15:49:47 · 115 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
题目描述Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 和有序链表化为BST方法一样,递归求解;注:中间必须要两个中间结点的后一个!!!实现代码: * Definition for binary tree * struct TreeNode { * ...原创 2018-03-27 21:25:32 · 109 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
题意:给定一个有序的链表,将其转换成平衡二叉搜索树思路: 二分法要构建一个平衡二叉树,二分法无疑是合适的,至于如何分是的代码简洁,就需要用到递归了。这题的关键是能找出当前链表的中间节点,然后再递归左右的子链表,开始的时候程序先计算链表总长,然后传入两个前后索引指针,最后每次递归找出中间节点即可。没有通过的代码: * Definition for sing...原创 2018-03-27 19:48:55 · 160 阅读 · 0 评论 -
平衡二叉树的判定
题目描述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 ...原创 2018-03-27 11:01:47 · 693 阅读 · 0 评论 -
二维平面求一条直线经过的最大点数
题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.问题描述:在一个二维平面上有n个点,求出现在同一直线上的点的最大个数分析:对每一个点计算与其他点(不包括与该点相同的点)连接成的直线的斜率,斜率重复出现的最大次数加成该点重复出现的个数,即为该点所...转载 2018-03-19 16:01:28 · 905 阅读 · 0 评论 -
Sum-root-to-leaf-Numbers
题目描述Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum...原创 2018-03-23 14:54:39 · 143 阅读 · 0 评论 -
Unique Binary Search Trees II
题目描述Given 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 ...原创 2018-03-29 20:56:54 · 84 阅读 · 0 评论 -
二叉树中序遍历
题目描述Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,3,2]. Note: Recursive solution is trivial...原创 2018-03-29 21:57:06 · 107 阅读 · 0 评论 -
二叉树后序遍历(栈)
题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note: Recursive solution is trivial, could...原创 2018-03-20 14:29:55 · 3834 阅读 · 0 评论 -
二叉树前序遍历(栈)
题目:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note: Recursive solution is trivial, could ...原创 2018-03-20 15:41:48 · 907 阅读 · 0 评论 -
二叉树最大路径和
题目描述Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return6. 这道题是求二叉树的最...原创 2018-03-24 20:56:01 · 3678 阅读 · 0 评论 -
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. If ...原创 2018-03-26 16:33:54 · 66 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II
题目描述Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use const...原创 2018-03-26 20:54:31 · 101 阅读 · 0 评论 -
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...原创 2018-03-26 22:10:58 · 156 阅读 · 0 评论 -
path sum 2
题目描述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 andsum = 22, 5 / \ ...原创 2018-03-27 09:39:18 · 237 阅读 · 0 评论 -
最小生成树的prim算法和kruskal算法
转载自:勿在浮沙筑高台http://blog.csdn.net/luoshixian099/article/details/51908175关于图的几个概念定义:连通图:在无向图中,若任意两个顶点vi与vj都有路径相通,则称该无向图为连通图。 强连通图:在有向图中,若任意两个顶点vi与vj都有路径相通,则称该有向图为强连通图。 连通网:在连通图中,若图的边具有一定的意义,每一条边都对应...转载 2018-08-19 15:13:45 · 1101 阅读 · 0 评论