随笔分类 -  Tree

摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or 阅读全文
posted @ 2020-02-03 02:10 北叶青藤 阅读(164) 评论(0) 推荐(0)
摘要:We are given a binary tree (with root node root), a target node, and an integer value K. Return a list of the values of all nodes that have a distance 阅读全文
posted @ 2020-02-02 23:55 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要:Find the second largest node in the BST 分析: 如果root有右节点,很明显第二大的node有可能在右子树里。唯一不满足的条件就是右子树只有一个node. 这个时候root就是第二大node. 所以我们需要把root(可能是第二大node)也传下去。 如果ro 阅读全文
posted @ 2019-07-30 13:23 北叶青藤 阅读(174) 评论(0) 推荐(0)
摘要:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be rep 阅读全文
posted @ 2019-07-08 06:32 北叶青藤 阅读(165) 评论(0) 推荐(0)
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or 阅读全文
posted @ 2019-07-06 11:56 北叶青藤 阅读(321) 评论(0) 推荐(0)
摘要:Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them. Two 阅读全文
posted @ 2019-07-04 03:06 北叶青藤 阅读(188) 评论(0) 推荐(0)
摘要:Given a BST, remove an extra edge to make it BST. 7 / \ 5 9 / \ / 3 8 阅读全文
posted @ 2019-06-22 11:25 北叶青藤 阅读(324) 评论(0) 推荐(0)
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwe 阅读全文
posted @ 2019-05-20 01:39 北叶青藤 阅读(241) 评论(0) 推荐(0)
摘要:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's 阅读全文
posted @ 2019-04-28 12:46 北叶青藤 阅读(214) 评论(0) 推荐(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. For example, 阅读全文
posted @ 2019-03-04 05:23 北叶青藤 阅读(144) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-04 04:10 北叶青藤 阅读(164) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-04 04:08 北叶青藤 阅读(154) 评论(0) 推荐(0)
摘要: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 n 阅读全文
posted @ 2019-02-14 14:53 北叶青藤 阅读(122) 评论(0) 推荐(0)
摘要:Path Sum I 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 g 阅读全文
posted @ 2016-12-31 01:12 北叶青藤 阅读(283) 评论(0) 推荐(0)
摘要:Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, ex 阅读全文
posted @ 2016-12-31 00:35 北叶青藤 阅读(153) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-12-22 06:04 北叶青藤 阅读(157) 评论(0) 推荐(0)
摘要:Given two Binary Search Trees, find common nodes in them. In other words, find intersection of two BSTs. Example: from: http://www.geeksforgeeks.org/p 阅读全文
posted @ 2016-12-19 14:17 北叶青藤 阅读(368) 评论(0) 推荐(0)
摘要:Find the sum of all left leaves in a given binary tree. Example: 阅读全文
posted @ 2016-12-02 05:56 北叶青藤 阅读(229) 评论(0) 推荐(0)
摘要:Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it up 阅读全文
posted @ 2016-11-15 00:33 北叶青藤 阅读(314) 评论(0) 推荐(0)
摘要:Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place. You can think of the left and right pointers as synonymous to the prede 阅读全文
posted @ 2016-11-11 07:54 北叶青藤 阅读(587) 评论(0) 推荐(0)