
Tree
文章平均质量分 73
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[Leetcode] Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-10-16 12:24:57 · 228 阅读 · 0 评论 -
[Leetcode]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 a file or memory buffer, or transmitted across a network connection link to be原创 2015-12-28 20:17:08 · 347 阅读 · 0 评论 -
[Leetcode] 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 \ 2 / 3return [1,2,3].Note: Recursive solution is triv原创 2015-09-14 11:14:32 · 245 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tre原创 2015-10-26 23:47:17 · 257 阅读 · 0 评论 -
[Leetcode]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 and sum = 22, 5 / \原创 2015-10-26 23:17:23 · 254 阅读 · 0 评论 -
[Leetcode]Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2015-09-16 17:46:40 · 293 阅读 · 0 评论 -
[Leetcode]Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n =原创 2015-10-27 16:41:59 · 877 阅读 · 0 评论 -
[Leetcode] Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If the原创 2015-09-22 12:51:54 · 267 阅读 · 0 评论 -
[Leetcode]Binary Tree Zigzag Level Order Traversal
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 binary tr原创 2015-10-27 00:03:15 · 335 阅读 · 0 评论 -
[Leetcode]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 \ 2 / 3return [1,3,2].Note: Recursive solution is trivi原创 2015-09-22 11:44:33 · 305 阅读 · 0 评论 -
[Leetcode]Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left;原创 2015-09-22 19:18:30 · 370 阅读 · 0 评论 -
[Leetcode]Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \原创 2015-10-11 17:04:06 · 255 阅读 · 0 评论 -
[Leetcode]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 next() will return the next smallest number in the BST.Note: next() and原创 2015-10-11 11:44:37 · 272 阅读 · 0 评论 -
[Leetcode] 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 to bottom.For example:Given the following binary tree, 1原创 2015-09-06 16:41:17 · 245 阅读 · 0 评论 -
[Leetcode]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-leaf path 1->2->3 which represents the number123.Find the total sum原创 2015-10-09 19:43:15 · 251 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tr原创 2015-10-24 14:44:54 · 291 阅读 · 0 评论 -
[Leetcode]Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find thekth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST原创 2015-08-20 22:20:59 · 288 阅读 · 0 评论 -
[Leetcode]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 \ 2 / 3return [3,2,1].Note: Recursive solution is tri原创 2015-12-03 18:10:20 · 249 阅读 · 0 评论