随笔分类 -  Tree

摘要:Description Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA). Each node will have a reference to its parent node. T 阅读全文
posted @ 2024-12-28 06:07 北叶青藤 阅读(19) 评论(0) 推荐(0)
摘要:Given a n * n matrix grid of 0's and 1's only. We want to represent the grid with a Quad-Tree. Return the root of the Quad-Tree representing the grid. 阅读全文
posted @ 2021-04-09 22:32 北叶青藤 阅读(60) 评论(0) 推荐(0)
摘要:Given a root of an N-ary tree, you need to compute the length of the diameter of the tree. The diameter of an N-ary tree is the length of the longest  阅读全文
posted @ 2021-04-08 08:34 北叶青藤 阅读(48) 评论(0) 推荐(0)
摘要:Given a binary search tree, return a balanced binary search tree with the same node values. A binary search tree is balanced if and only if the depth 阅读全文
posted @ 2021-03-29 05:43 北叶青藤 阅读(48) 评论(0) 推荐(0)
摘要:You need to construct a binary tree from a string consisting of parenthesis and integers. The whole input represents a binary tree. It contains an int 阅读全文
posted @ 2021-03-29 01:11 北叶青藤 阅读(35) 评论(0) 推荐(0)
摘要:Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is compl 阅读全文
posted @ 2021-03-29 01:08 北叶青藤 阅读(80) 评论(0) 推荐(0)
摘要:Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus 阅读全文
posted @ 2021-03-28 06:52 北叶青藤 阅读(52) 评论(0) 推荐(0)
摘要:Given the root of a binary tree, find the maximum average value of any subtree of that tree. (A subtree of a tree is any node of that tree plus all it 阅读全文
posted @ 2021-03-13 13:42 北叶青藤 阅读(147) 评论(0) 推荐(0)
摘要:A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possibl 阅读全文
posted @ 2021-03-13 08:13 北叶青藤 阅读(51) 评论(0) 推荐(0)
摘要:Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the g 阅读全文
posted @ 2020-12-27 03:43 北叶青藤 阅读(91) 评论(0) 推荐(0)
摘要:You are given some lists of regions where the first region of each list includes all other regions in that list. Naturally, if a region X contains ano 阅读全文
posted @ 2020-12-27 00:54 北叶青藤 阅读(118) 评论(0) 推荐(0)
摘要:Given the root of a binary tree, find the maximum value V for which there exists different nodes A and B where V = |A.val - B.val| and A is an ancesto 阅读全文
posted @ 2020-04-05 10:46 北叶青藤 阅读(268) 评论(0) 推荐(0)
摘要:Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if i 阅读全文
posted @ 2020-03-07 15:07 北叶青藤 阅读(173) 评论(0) 推荐(0)
摘要:Given an n-ary tree, return the level order traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversa 阅读全文
posted @ 2020-02-18 07:30 北叶青藤 阅读(172) 评论(0) 推荐(0)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic 阅读全文
posted @ 2020-02-07 08:11 北叶青藤 阅读(135) 评论(0) 推荐(0)
摘要:Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is g 阅读全文
posted @ 2020-02-07 07:50 北叶青藤 阅读(274) 评论(0) 推荐(0)
摘要:给两个bst,把它们的值按照从小到大打印。 1 public static void print2BSTInorder(TreeNode n1, TreeNode n2, List<Integer> result) { 2 Stack<TreeNode> stack1 = new Stack<>() 阅读全文
posted @ 2020-02-07 07:02 北叶青藤 阅读(97) 评论(0) 推荐(0)
摘要:Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: 阅读全文
posted @ 2020-02-06 09:39 北叶青藤 阅读(529) 评论(0) 推荐(0)
摘要:有个N叉树是个大食堂的地图。节点有的是餐馆,有的不是,在输入里面用boolean表示了。每个父节点到子节点的距离都是一。你作为一个吃货,从根节点出发,要去所有的餐馆尝尝,需要的最短路径是多少。楼主DFS返回两个量,一个是这个节点为根的树要吃完需要的走多长的路,另一个是一个flag表示这个子树里面有没 阅读全文
posted @ 2020-02-06 06:22 北叶青藤 阅读(185) 评论(0) 推荐(0)
摘要:Given a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the largest depth possibl 阅读全文
posted @ 2020-02-06 06:11 北叶青藤 阅读(113) 评论(0) 推荐(0)