
binary tree
文章平均质量分 71
小榕流光
这个作者很懒,什么都没留下…
展开
-
[leetcode] 235. Lowest Common Ancestor of a Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Accord原创 2015-12-25 03:59:26 · 434 阅读 · 0 评论 -
[leetcode] 116. Populating Next Right Pointers in Each Node 解题报告
题目链接:https://leetcode.com/problems/populating-next-right-pointers-in-each-node/Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkN原创 2016-01-11 16:00:02 · 393 阅读 · 0 评论 -
[leetcode] 156. Binary Tree Upside Down 解题报告
题目链接: https://leetcode.com/problems/binary-tree-upside-down/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 e原创 2016-03-21 13:23:13 · 3176 阅读 · 0 评论 -
[leetcode] 94. Binary Tree Inorder Traversal 解题报告
题目链接:https://leetcode.com/problems/binary-tree-inorder-traversal/Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1原创 2016-01-12 04:09:10 · 465 阅读 · 0 评论 -
[leetcode] 250. Count Univalue Subtrees 解题报告
题目链接: https://leetcode.com/problems/count-univalue-subtrees/Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value原创 2016-03-21 13:44:53 · 3298 阅读 · 0 评论 -
[leetcode] 285. Inorder Successor in BST 解题报告
题目链接: https://leetcode.com/problems/inorder-successor-in-bst/Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no i原创 2016-03-14 14:39:11 · 4413 阅读 · 0 评论 -
[leetcode] 314. Binary Tree Vertical Order Traversal 解题报告
题目链接:https://leetcode.com/problems/binary-tree-vertical-order-traversal/Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).原创 2016-02-28 16:51:34 · 2855 阅读 · 0 评论 -
[leetcode] 270. Closest Binary Search Tree Value 解题报告
题目链接:https://leetcode.com/problems/closest-binary-search-tree-value/Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:原创 2016-06-15 15:08:53 · 1400 阅读 · 0 评论 -
[leetcode] 366. Find Leaves of Binary Tree 解题报告
题目链接: https://leetcode.com/problems/find-leaves-of-binary-tree/Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps until the tree is empty.Examp原创 2016-06-25 11:17:49 · 4900 阅读 · 0 评论 -
[leetcode] 199. Binary Tree Right Side View 解题报告
题目链接:https://leetcode.com/problems/binary-tree-right-side-view/Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top原创 2016-01-12 05:26:20 · 900 阅读 · 0 评论 -
[leetcode] 222. Count Complete Tree Nodes 解题报告
题目链接:https://leetcode.com/problems/count-complete-tree-nodes/Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binar原创 2016-01-12 06:57:17 · 796 阅读 · 0 评论 -
[leetcode] 315. Count of Smaller Numbers After Self 解题报告
题目链接: https://leetcode.com/problems/count-of-smaller-numbers-after-self/You are given an integer array nums and you have to return a new counts array. The counts array has the property where cou原创 2016-05-05 10:43:51 · 6996 阅读 · 0 评论 -
[leetcode] 255. Verify Preorder Sequence in Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.原创 2016-03-19 06:12:50 · 4161 阅读 · 0 评论 -
[leetcode] 112. Path Sum 解题报告
题目链接:https://leetcode.com/problems/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.原创 2015-12-24 15:55:38 · 401 阅读 · 0 评论 -
[leetcode] 110. Balanced Binary Tree 解题报告
题目链接:https://leetcode.com/problems/balanced-binary-tree/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原创 2015-12-24 17:38:03 · 451 阅读 · 0 评论 -
[leetcode] 230. Kth Smallest Element in a BST 解题报告
题目链接:https://leetcode.com/problems/kth-smallest-element-in-a-bst/Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is原创 2016-01-11 14:34:34 · 622 阅读 · 0 评论 -
[leetcode] 272. Closest Binary Search Tree Value II 解题报告
题目链接:https://leetcode.com/problems/closest-binary-search-tree-value-ii/Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Note:原创 2016-03-25 16:59:18 · 4149 阅读 · 0 评论 -
[leetcode] 100. Same Tree 解题报告
题目链接:https://leetcode.com/problems/same-tree/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 identic原创 2015-12-24 15:40:49 · 453 阅读 · 0 评论 -
[leetcode] 287. Find the Duplicate Number 解题报告
题目链接:https://leetcode.com/problems/find-the-duplicate-number/Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate nu原创 2016-01-14 14:36:22 · 855 阅读 · 0 评论 -
[leetcode] 297. Serialize and Deserialize Binary Tree 解题报告
题目链接:https://leetcode.com/problems/serialize-and-deserialize-binary-tree/Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in原创 2016-03-06 04:31:30 · 1046 阅读 · 0 评论 -
[leetcode] 333. Largest BST Subtree 解题报告
题目链接: https://leetcode.com/problems/largest-bst-subtree/Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of node原创 2016-06-22 05:21:59 · 5197 阅读 · 0 评论 -
[leetcode] 98. Validate Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/validate-binary-search-tree/Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtre原创 2015-12-26 10:29:28 · 673 阅读 · 0 评论 -
[leetcode] 106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告
题目链接:https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume原创 2016-06-12 16:13:48 · 478 阅读 · 0 评论 -
[leetcode] 105. Construct Binary Tree from Preorder and Inorder Traversal 解题报告
题目链接:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume t原创 2016-01-04 17:27:05 · 430 阅读 · 0 评论 -
[leetcode] 102. Binary Tree Level Order Traversal 解题报告
题目链接:https://leetcode.com/problems/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原创 2015-12-24 20:29:30 · 409 阅读 · 0 评论 -
[leetcode] 111. Minimum Depth of Binary Tree 解题报告
题目链接:https://leetcode.com/problems/minimum-depth-of-binary-tree/Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root nod原创 2015-12-24 16:16:57 · 1102 阅读 · 0 评论 -
[leetcode] 173. Binary Search Tree Iterator 解题报告
题目链接:https://leetcode.com/problems/binary-search-tree-iterator/Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling ne原创 2016-01-12 01:29:50 · 2278 阅读 · 0 评论 -
[leetcode] 117. Populating Next Right Pointers in Each Node II 解题报告
题目链接:https://leetcode.com/problems/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 bina原创 2016-01-13 06:36:40 · 1905 阅读 · 0 评论 -
[leetcode] 145. Binary Tree Postorder Traversal 解题报告
题目链接:https://leetcode.com/problems/binary-tree-postorder-traversal/Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1原创 2016-01-12 14:24:55 · 592 阅读 · 1 评论 -
[leetcode] 236. Lowest Common Ancestor of a Binary Tree 解题报告
题目链接:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the defin原创 2016-01-12 12:03:57 · 1088 阅读 · 0 评论 -
[leetcode] 144. Binary Tree Preorder Traversal 解题报告
题目链接:https://leetcode.com/problems/binary-tree-preorder-traversal/Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1原创 2016-01-11 11:28:28 · 505 阅读 · 0 评论 -
[leetcode] 108. Convert Sorted Array to Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:前面有一题将有序链表转换原创 2016-01-11 10:56:13 · 530 阅读 · 0 评论 -
[leetcode] 104. Maximum Depth of Binary Tree 解题报告
题目链接:https://leetcode.com/problems/maximum-depth-of-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原创 2015-12-24 17:45:41 · 369 阅读 · 0 评论 -
[leetcode] 331. Verify Preorder Serialization of a Binary Tree 解题报告
题目链接: https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record原创 2016-05-10 08:53:38 · 1832 阅读 · 0 评论 -
[leetcode] 124. Binary Tree Maximum Path Sum 解题报告
题目链接: https://leetcode.com/problems/binary-tree-maximum-path-sum/Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some startin原创 2016-05-05 13:53:18 · 976 阅读 · 0 评论 -
[leetcode] 99. Recover Binary Search Tree 解题报告
题目链接:https://leetcode.com/problems/recover-binary-search-tree/Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A sol原创 2016-01-14 13:27:39 · 2598 阅读 · 0 评论 -
[leetcode] 113. Path Sum II 解题报告
题目链接:https://leetcode.com/problems/path-sum-ii/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 a原创 2015-12-25 04:43:44 · 487 阅读 · 0 评论 -
[leetcode] 129. Sum Root to Leaf Numbers 解题报告
题目链接:https://leetcode.com/problems/sum-root-to-leaf-numbers/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-l原创 2015-12-26 10:45:01 · 474 阅读 · 0 评论 -
[leetcode] 257. Binary Tree Paths 解题报告
题目链接:https://leetcode.com/problems/binary-tree-paths/Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5原创 2015-12-24 16:50:45 · 424 阅读 · 0 评论 -
[leetcode] 101. Symmetric Tree 解题报告
题目链接:https://leetcode.com/problems/symmetric-tree/Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric:原创 2015-12-24 15:30:34 · 482 阅读 · 0 评论