
tree
文章平均质量分 67
Peng_maple
这个作者很懒,什么都没留下…
展开
-
[LeetCode] 144. Binary Tree Preorder Traversal
Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3...原创 2018-09-02 15:21:15 · 225 阅读 · 0 评论 -
[LeetCode] 199. Binary Tree Right Side View
Binary Tree Right Side ViewGiven 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,...原创 2018-09-03 21:36:45 · 144 阅读 · 0 评论 -
[LeetCode] 222. Count Complete Tree Nodes
Count Complete Tree NodesGiven a complete binary tree, count the number of nodes. Note: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the ...原创 2018-09-03 22:32:19 · 136 阅读 · 0 评论 -
[LeetCode] 173. Binary Search Tree Iterator
Binary Search Tree IteratorImplement 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 next smallest number ...原创 2018-09-06 09:15:39 · 160 阅读 · 0 评论 -
[LeetCode] 230. Kth Smallest Element in a BST
Kth Smallest Element in a BSTGiven 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....原创 2018-09-06 10:53:02 · 169 阅读 · 0 评论 -
[LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia:...原创 2018-09-06 11:52:50 · 168 阅读 · 0 评论 -
[LeetCode] 236. Lowest Common Ancestor of a Binary Tree
Lowest Common Ancestor of a Binary TreeGiven 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...原创 2018-09-06 23:20:00 · 130 阅读 · 0 评论 -
[LeetCode] 623. Add One Row to Tree
Add One Row to TreeGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1. The adding rule is: give...原创 2018-09-11 09:06:04 · 158 阅读 · 0 评论 -
[LeetCode] 515. Find Largest Value in Each Tree Row
Find Largest Value in Each Tree RowYou need to find the largest value in each row of a binary tree. 解析找到每一层的最大节点值。解法1:层序遍历直接层次遍历每一层,获得最大值。class Solution {public: vector<int> ...原创 2018-09-11 09:33:35 · 167 阅读 · 0 评论 -
[LeetCode] 655. Print Binary Tree
Maximum Binary TreePrint a binary tree in an m*n 2D string array following these rules:The row number m should be equal to the height of the given binary tree.The column number n should always be ...原创 2018-11-12 23:26:05 · 176 阅读 · 0 评论 -
[LeetCode] 652. Find Duplicate Subtrees
Find Duplicate SubtreesGiven 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 trees are duplicate if th...原创 2018-11-10 11:52:02 · 276 阅读 · 0 评论 -
[LeetCode] 654. Maximum Binary Tree
Maximum Binary TreeGiven an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum...原创 2018-11-10 19:49:09 · 131 阅读 · 0 评论 -
[LeetCode] 450. Delete Node in a BST
Delete Node in a BSTGiven 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 the BST.Basically, the deletio...原创 2018-11-07 21:51:33 · 324 阅读 · 0 评论 -
[LeetCode] 501. Find Mode in Binary Search Tree
Find Mode in Binary Search TreeGiven a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The ...原创 2018-11-07 23:39:27 · 138 阅读 · 0 评论 -
[LeetCode] 437. Path Sum III
Path Sum IIIYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf,...原创 2018-11-06 00:03:58 · 162 阅读 · 0 评论 -
[LeetCode] 662. Maximum Width of Binary Tree
Maximum Width of Binary TreeGiven a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same s...原创 2018-11-13 23:55:57 · 173 阅读 · 0 评论 -
[LeetCode] 508. Most Frequent Subtree Sum
Most Frequent Subtree SumGiven the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree ro...原创 2018-11-08 22:59:29 · 648 阅读 · 0 评论 -
[LeetCode] 145. Binary Tree Postorder Traversal
Binary Tree Postorder TraversalGiven a binary tree, return the postorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [3,2...原创 2018-09-03 21:14:57 · 147 阅读 · 0 评论 -
[LeetCode] 124. Binary Tree Maximum Path Sum
Binary Tree Maximum Path SumGiven a non-empty binary 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 al...原创 2018-09-08 23:20:25 · 147 阅读 · 0 评论 -
[LeetCode] 129. Sum Root to Leaf Numbers
Sum Root to Leaf NumbersGiven 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-&gt;2-&gt;3 which represents the ...原创 2018-09-02 14:40:14 · 128 阅读 · 0 评论 -
[LeetCode] 117. Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node IIGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next poin...原创 2018-09-02 11:16:35 · 164 阅读 · 0 评论 -
[LeetCode] 110. Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place. For example, given the following tree: 解析把二叉树展开成链表,根据展开后形成的链表的顺序分析出是先序遍历。解法1从根节点出发,先检测其左子...原创 2018-09-01 15:57:59 · 150 阅读 · 0 评论 -
[LeetCode] 116. Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer...原创 2018-09-01 15:21:31 · 150 阅读 · 0 评论 -
[LeetCode] 113. Path Sum II
Path Sum IIGiven 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 ...原创 2018-09-01 13:59:57 · 163 阅读 · 0 评论 -
[LeetCode] 110. Balanced Binary Tree
Balanced Binary TreeGiven 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 ...原创 2018-09-01 11:03:06 · 130 阅读 · 0 评论 -
[LeetCode] 106. Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree....原创 2018-09-01 10:33:53 · 137 阅读 · 0 评论 -
[LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. ...原创 2018-09-01 00:09:13 · 154 阅读 · 0 评论 -
[LeetCode] 103. Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order TraversalGiven 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 alternat...原创 2018-08-31 23:42:11 · 127 阅读 · 0 评论 -
[LeetCode] 102. Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). Example: Given binary tree [3,9,20,null,nu...原创 2018-08-31 22:09:18 · 109 阅读 · 0 评论 -
[LeetCode] 99. Recover Binary Search Tree
Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example: Input: [1,3,null,null,2] 1 / ...原创 2018-08-31 21:36:40 · 118 阅读 · 0 评论 -
[LeetCode] 98. Validate Binary Search Tree
Validate Binary Search TreeGiven 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 keys le...原创 2018-08-31 10:44:51 · 165 阅读 · 0 评论 -
[LeetCode] 95. Unique Binary Search Trees II
Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n. Example: Input: 3 Output: [ [1,null,3,2], ...原创 2018-08-29 14:18:03 · 145 阅读 · 0 评论 -
[LeetCode] 96. Unique Binary Search Trees
Unique Binary Search Trees Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a t...原创 2018-08-29 11:31:55 · 113 阅读 · 0 评论 -
[LeetCode] 94. Binary Tree Inorder Traversal
Binary Tree Inorder Traversal 本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 ...原创 2018-08-29 00:46:14 · 186 阅读 · 0 评论 -
[LeetCode] 337. House Robber III
House Robber IIIThe 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 h...原创 2018-09-11 23:11:49 · 220 阅读 · 0 评论 -
[LeetCode] 653. Two Sum IV - Input is a BST
Two Sum IV - Input is a BSTGiven a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.解析找到二叉树中两个数之和是否等于目标值。...原创 2018-11-08 23:35:40 · 147 阅读 · 0 评论