
树
文章平均质量分 71
ZWB626
这个作者很懒,什么都没留下…
展开
-
根节点到叶子节点的和值(根节点逐步升位)
package leetcode;/*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 number12...原创 2018-12-04 16:32:20 · 1286 阅读 · 0 评论 -
统计1-n的数目元素作为节点的树的种类个数
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-12-17 15:40:30 · 328 阅读 · 0 评论 -
判断平衡二叉树
package leetcode;public class Balanced_binary_tree { public static void main(String[] args) { } public boolean isBalanced(TreeNode root) { if(root == null) { ...原创 2018-12-17 16:19:39 · 191 阅读 · 0 评论 -
二叉树的层序遍历
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-12-17 21:14:36 · 369 阅读 · 1 评论 -
按之形顺序打印二叉树
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 binary tre...原创 2019-01-11 23:10:16 · 248 阅读 · 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 devise a ...转载 2019-01-24 21:37:26 · 441 阅读 · 0 评论 -
判断一个二叉树是不是二叉搜索树
package niuke.day1;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 ...转载 2019-01-25 01:22:59 · 286 阅读 · 0 评论 -
construct-binary-tree-from-inorder-and-postorder-traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.package leetcode;public class Construct_binary_tree_from...原创 2019-01-09 21:51:26 · 279 阅读 · 0 评论 -
把从1到n的所有情况构成的二叉搜索树添加到队列中
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 3 ...转载 2019-01-26 00:59:56 · 505 阅读 · 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. package lee...原创 2018-12-16 21:21:08 · 689 阅读 · 0 评论 -
把二叉树的每一层的节点进行横向连接
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-12-16 18:39:10 · 488 阅读 · 1 评论 -
二叉树的前序遍历(迭代)
package leetcode;/*Given a binary tree, return the preorder traversal of its nodes' values*/import java.util.ArrayList;public class Binary_tree_preorder_traversal { public static void main...原创 2018-12-03 22:20:14 · 436 阅读 · 0 评论 -
后序遍历二叉树
package leetcode;/*Given a binary tree, return the postorder traversal of its nodes' values.*/import java.util.ArrayList;public class Binary_tree_postorder_traversal { public static void mai...原创 2018-12-03 22:10:27 · 177 阅读 · 0 评论 -
判断二叉树的路径和是否和给定数值相等
package niuke.day1;import java.util.Stack;/*Given a binary tree and a sum, determine if the tree has a root-to-leaf path suchthat adding up all the values along the path equals the given sum.For ...原创 2018-12-06 22:47:35 · 422 阅读 · 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-12-19 19:11:10 · 738 阅读 · 0 评论 -
二叉树的每一层横向节点用next连接(进阶版)
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 constant extra ...转载 2018-12-19 21:58:26 · 402 阅读 · 0 评论 -
二叉树的层序遍历(但是从下到上的放到数组中)
package niuke.day1;import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;import java.util.Stack;public class Binary_tree_level_order_traversal_ii { public static v...原创 2018-12-20 22:48:48 · 924 阅读 · 0 评论 -
二叉树--求出所有路径,它们的和是给定的数值
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-12-15 22:06:17 · 346 阅读 · 0 评论 -
求二叉树的最大深度
package leetcode;/*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.*/public class M...原创 2018-12-16 15:08:36 · 332 阅读 · 0 评论 -
插入排序
package eighty;public class Onefiveeight { public static void main(String[] args) { int[] a = {1,43,23,56,76,23,12,3,76,345,9,21}; int N = a.length; boolean flag = false;...原创 2018-11-15 22:32:43 · 180 阅读 · 0 评论