Tree
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
742 Closest Leaf in a Binary Tree
1 题目Given a binary treewhere every node has a unique value, and a target keyk, find the value of the nearest leaf node to targetkin the tree.Here,nearestto a leaf means the least number of e...原创 2020-01-06 10:44:09 · 128 阅读 · 0 评论 -
124 Binary Tree Maximum Path Sum
1 题目Given anon-emptybinary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child con...原创 2019-12-20 08:02:53 · 70 阅读 · 0 评论 -
1104 Path In Zigzag Labelled Binary Tree
1 题目In an infinite binary tree where every node has two children, the nodes are labelled in row order.In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, w...原创 2019-11-26 14:33:59 · 88 阅读 · 0 评论 -
572 Subtree of Another Tree
1 题目Given two non-empty binary treessandt, check whether treethas exactly the same structure and node values with a subtree ofs. A subtree ofsis a tree consists of a node insand all of thi...原创 2019-11-24 10:17:54 · 60 阅读 · 0 评论 -
107 Binary Tree Level Order Traversal II
1 题目Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree[3,9,20,null,nul...原创 2019-04-26 12:10:12 · 238 阅读 · 0 评论 -
222 Count Complete Tree Nodes
1 题目Given a complete binary tree, count the number of nodes.Note:Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is complet...原创 2019-04-22 14:33:49 · 64 阅读 · 0 评论 -
116 Populating Next Right Pointers in Each Node
1 题目You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *le...原创 2019-04-15 15:42:09 · 74 阅读 · 0 评论 -
230 Kth Smallest Element in a BST
1 题目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 total elements.Example 1:Input: root ...原创 2019-04-23 13:17:49 · 88 阅读 · 0 评论 -
236 Lowest Common Ancestor of a Binary Tree
1 题目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 lowest common ancestor is defined between two n...原创 2019-04-23 15:17:02 · 51 阅读 · 0 评论 -
108 Convert Sorted Array to Binary Search Tree
1 题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth ...原创 2019-05-06 16:26:02 · 51 阅读 · 0 评论 -
110 Balanced Binary Tree
1 题目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 which the depth of the two subtrees ofeverynode never...原创 2019-05-06 17:02:07 · 50 阅读 · 0 评论 -
404 Sum of Left Leaves
1 题目Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Retu...原创 2019-05-07 15:47:58 · 62 阅读 · 0 评论 -
337 House Robber III
1 题目The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After ...原创 2019-07-04 22:52:16 · 90 阅读 · 0 评论 -
235 Lowest Common Ancestor of a Binary Search Tree
1 题目Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: “The lowest common ancestor is defined be...原创 2019-04-26 10:39:49 · 56 阅读 · 0 评论 -
257 Binary Tree Paths
1 题目Given a binary tree, return all root-to-leaf paths.Note:A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: A...原创 2019-04-26 10:10:32 · 58 阅读 · 0 评论 -
95 Unique Binary Search Trees II
1 題目Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.Example:Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], ...原创 2019-04-17 10:51:05 · 62 阅读 · 0 评论 -
114 Flatten Binary Tree to Linked List
1 题目Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5 / \ \3 4 6The flattened tree should look like:1 \ 2 ...原创 2019-04-05 15:42:01 · 74 阅读 · 0 评论 -
98 Validate Binary Search Tree
1 题目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 keysless thanthe node's key....原创 2019-04-01 17:49:11 · 56 阅读 · 0 评论 -
105 Construct Binary Tree from Preorder and Inorder Traversal
1 题目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, givenpreorder =[3,9,20,15,7]inorder ...原创 2019-04-01 21:35:46 · 53 阅读 · 0 评论 -
106 Construct Binary Tree from Inorder and Postorder Traversal
1 题目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, giveninorder =[9,3,15,20,7]postorde...原创 2019-04-01 21:37:45 · 47 阅读 · 0 评论 -
102 Binary Tree Level Order Traversal
1 题目Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree[3,9,20,null,null,15,7], 3 / \ 9 ...原创 2019-04-01 22:05:50 · 55 阅读 · 0 评论 -
113 Path Sum II
1 题目Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Note:A leaf is a node with no children.Example:Given the below binary tree andsum = ...原创 2019-04-02 11:32:37 · 55 阅读 · 0 评论 -
117 Populating Next Right Pointers in Each Node II
1 题目Given a binary treestruct Node { int val; Node *left; Node *right; Node *next;}Populate each next pointer to point to its next right node. If there is no next right node, the next p...原创 2019-04-15 16:18:56 · 72 阅读 · 0 评论 -
129 Sum Root to Leaf Numbers
1 题目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 which represents the number 123.Find t...原创 2019-04-15 16:28:06 · 71 阅读 · 0 评论 -
103 Binary Tree Zigzag Level Order Traversal
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 bin...原创 2019-04-12 12:53:51 · 70 阅读 · 0 评论 -
199 Binary Tree Right Side View
1 题目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 to bottom.Example:Input: [1,2,3,null,5,null,4]Output: [1...原创 2019-04-12 16:04:51 · 70 阅读 · 0 评论 -
96. Unique Binary Search Trees
1 题目Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...原创 2019-04-16 14:14:06 · 60 阅读 · 0 评论 -
144 Binary Tree Preorder Traversal
1 题目Given a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive solution is trivial, c...原创 2019-04-16 15:49:12 · 60 阅读 · 0 评论 -
94 Binary Tree Inorder Traversal
1 题目Given a binary tree, return theinordertraversal of its nodes' values.2 尝试解class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vector<int> resul...原创 2019-03-29 09:19:02 · 54 阅读 · 0 评论