随笔分类 -  Tree

摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. 阅读全文
posted @ 2018-11-24 22:11 Veritas_des_Liberty 阅读(303) 评论(0) 推荐(0)
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th 阅读全文
posted @ 2018-11-24 18:31 Veritas_des_Liberty 阅读(185) 评论(0) 推荐(0)
摘要:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the 阅读全文
posted @ 2018-11-24 12:22 Veritas_des_Liberty 阅读(221) 评论(0) 推荐(0)
摘要:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Retu 阅读全文
posted @ 2018-11-24 11:40 Veritas_des_Liberty 阅读(200) 评论(0) 推荐(0)
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n 阅读全文
posted @ 2018-11-24 10:51 Veritas_des_Liberty 阅读(235) 评论(0) 推荐(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 阅读全文
posted @ 2018-11-24 09:58 Veritas_des_Liberty 阅读(223) 评论(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 @ 2018-11-23 20:45 Veritas_des_Liberty 阅读(316) 评论(0) 推荐(0)
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文
posted @ 2018-11-23 15:50 Veritas_des_Liberty 阅读(179) 评论(0) 推荐(0)
摘要:Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL 阅读全文
posted @ 2018-11-22 22:40 Veritas_des_Liberty 阅读(255) 评论(0) 推荐(0)
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its ne 阅读全文
posted @ 2018-11-22 22:28 Veritas_des_Liberty 阅读(273) 评论(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 @ 2018-11-22 19:08 Veritas_des_Liberty 阅读(184) 评论(0) 推荐(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. For example, 阅读全文
posted @ 2018-11-22 18:04 Veritas_des_Liberty 阅读(207) 评论(0) 推荐(0)
摘要: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. N 阅读全文
posted @ 2018-11-21 22:09 Veritas_des_Liberty 阅读(211) 评论(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 @ 2018-11-21 18:33 Veritas_des_Liberty 阅读(196) 评论(0) 推荐(0)
摘要:"Top-down" Solution Here is the pseudocode for the recursion function maximum_depth(root, depth): 1. return if root is null 2. if root is a leaf node: 阅读全文
posted @ 2018-11-21 18:11 Veritas_des_Liberty 阅读(297) 评论(0) 推荐(0)
摘要:Preorder: Approach #1: Recurisive. Approach #2: Iteratively.[Java] Approach #3: Morris Traversal.[C++] Using Morris Traversal can don't use recurisive 阅读全文
posted @ 2018-11-18 18:20 Veritas_des_Liberty 阅读(234) 评论(0) 推荐(0)
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Follow up: Recursive solution is trivial, could you do it iteratively 阅读全文
posted @ 2018-11-11 21:11 Veritas_des_Liberty 阅读(182) 评论(0) 推荐(0)