随笔分类 -  Tree

摘要:1.题目描述 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, ... 阅读全文
posted @ 2013-08-17 23:46 曾见绝美的阳光 阅读(224) 评论(0) 推荐(0)
摘要:昨天临近要睡觉的时候做了一个leetcode题目,“Recover BST”,算法很容易就想到了,直接找出两个异常点就好了,但是我写的算法是用栈实现的非递归遍历,空间复杂度是O(N),虽然比递归的要好点,但是题目说明里面那句“如果能用constant space ”却让我百思不得其解。难道我的解法不是最精简的? 我的解法说白了就是个preorder traversal,难道有可以不用traver... 阅读全文
posted @ 2013-08-16 14:26 曾见绝美的阳光 阅读(2051) 评论(1) 推荐(0)
摘要:1.题目描述 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its s... 阅读全文
posted @ 2013-08-15 23:51 曾见绝美的阳光 阅读(255) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follo... 阅读全文
posted @ 2013-08-15 22:16 曾见绝美的阳光 阅读(240) 评论(1) 推荐(0)
摘要:1.题目描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considere... 阅读全文
posted @ 2013-08-15 21:41 曾见绝美的阳光 阅读(284) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example... 阅读全文
posted @ 2013-08-15 20:59 曾见绝美的阳光 阅读(236) 评论(0) 推荐(0)
摘要:1.题目描述 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may ass... 阅读全文
posted @ 2013-08-15 01:02 曾见绝美的阳光 阅读(217) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from lea... 阅读全文
posted @ 2013-08-15 00:30 曾见绝美的阳光 阅读(220) 评论(0) 推荐(0)
摘要:1.题目描述 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 2.解法分析 ... 阅读全文
posted @ 2013-08-15 00:02 曾见绝美的阳光 阅读(218) 评论(0) 推荐(0)
摘要:1.题目描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. ... 阅读全文
posted @ 2013-08-14 23:35 曾见绝美的阳光 阅读(437) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree i... 阅读全文
posted @ 2013-08-13 21:35 曾见绝美的阳光 阅读(201) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest p... 阅读全文
posted @ 2013-08-13 21:04 曾见绝美的阳光 阅读(178) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For... 阅读全文
posted @ 2013-08-13 20:29 曾见绝美的阳光 阅读(212) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree, flatten it to a linked list in-place. For example, Given ... 阅读全文
posted @ 2013-08-13 15:12 曾见绝美的阳光 阅读(297) 评论(0) 推荐(0)
摘要:1.题目描述 Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any b... 阅读全文
posted @ 2013-08-12 14:39 曾见绝美的阳光 阅读(496) 评论(0) 推荐(0)
摘要:1.题目描述 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; ... 阅读全文
posted @ 2013-08-12 13:07 曾见绝美的阳光 阅读(259) 评论(0) 推荐(0)