
Tree
文章平均质量分 75
jialuyyy
这个作者很懒,什么都没留下…
展开
-
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 subt原创 2015-06-01 10:58:22 · 187 阅读 · 0 评论 -
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 leve原创 2015-06-06 22:26:15 · 183 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.Using binary search to solve th原创 2015-06-06 22:23:12 · 180 阅读 · 0 评论 -
Binary Tree Upside Down
Binary Tree Upside DownGiven 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 empty, flip it upside down a原创 2015-06-06 22:44:30 · 240 阅读 · 0 评论 -
Count Complete Tree Nodes
Count Complete Tree NodesGiven a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly原创 2015-06-07 11:50:19 · 292 阅读 · 0 评论 -
Validate Binary Search Tree
Validate Binary Search Tree原创 2015-06-07 12:41:42 · 236 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1原创 2015-06-07 23:02:06 · 212 阅读 · 0 评论 -
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.For example:Given t原创 2015-06-07 10:30:24 · 174 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node I, II
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }P原创 2015-06-07 22:42:01 · 209 阅读 · 0 评论 -
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 e原创 2015-07-03 02:20:13 · 258 阅读 · 0 评论 -
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.Note:A solution using O(n)原创 2015-07-02 22:09:17 · 276 阅读 · 0 评论 -
preorder, inorder, postorder traversal
preorder, inorder, postorder traversalGiven a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3原创 2015-06-04 05:21:20 · 278 阅读 · 0 评论 -
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 1 / \ 2 5 / \ \ 3 4 6Th原创 2015-06-04 05:34:08 · 201 阅读 · 0 评论 -
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原创 2015-06-04 06:46:07 · 193 阅读 · 0 评论 -
Symmetric Tree
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2015-06-01 11:09:38 · 203 阅读 · 0 评论 -
Serialize and Deserialize a binary tree
Serialize and Deserialize a binary treevoid Serialize(TreeNode node) { if (node == null) { System.out.print("#" + " "); return; } System.out.print(node.val + " "); Serialize(nod原创 2015-06-21 00:47:53 · 219 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal IIGiven a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For examp原创 2015-06-02 22:04:29 · 242 阅读 · 0 评论 -
Depth of binary tree
Maximum depth of binary tree and minimum depth of binary tree.Maximum/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeN原创 2015-06-02 22:58:03 · 184 阅读 · 0 评论 -
Same Tree
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2015-06-02 22:00:16 · 182 阅读 · 0 评论 -
Path Sum
Path SumGiven 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.For example:Given the below binary原创 2015-06-03 00:22:45 · 394 阅读 · 0 评论 -
Unique Binary Search Trees
Unique Binary Search TreesGiven 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原创 2015-06-03 06:05:44 · 185 阅读 · 0 评论 -
Path Sum II
5原创 2015-06-03 11:58:10 · 177 阅读 · 0 评论 -
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 smalle原创 2015-06-03 09:36:37 · 170 阅读 · 0 评论 -
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->2->3 which repre原创 2015-06-04 04:44:24 · 306 阅读 · 0 评论 -
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 t原创 2015-06-04 05:50:10 · 288 阅读 · 0 评论 -
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原创 2015-07-12 22:58:05 · 286 阅读 · 0 评论