随笔分类 - Tree
摘要:1.题目描述 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, ...
阅读全文
摘要:昨天临近要睡觉的时候做了一个leetcode题目,“Recover BST”,算法很容易就想到了,直接找出两个异常点就好了,但是我写的算法是用栈实现的非递归遍历,空间复杂度是O(N),虽然比递归的要好点,但是题目说明里面那句“如果能用constant space ”却让我百思不得其解。难道我的解法不是最精简的? 我的解法说白了就是个preorder traversal,难道有可以不用traver...
阅读全文
摘要:1.题目描述 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its s...
阅读全文
摘要:1.题目描述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follo...
阅读全文
摘要:1.题目描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considere...
阅读全文
摘要:1.题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example...
阅读全文
摘要:1.题目描述 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may ass...
阅读全文
摘要: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...
阅读全文
摘要:1.题目描述 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 2.解法分析 ...
阅读全文
摘要:1.题目描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. ...
阅读全文
摘要:1.题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree i...
阅读全文
摘要:1.题目描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest p...
阅读全文
摘要:1.题目描述 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For...
阅读全文
摘要:1.题目描述 Given a binary tree, flatten it to a linked list in-place. For example, Given ...
阅读全文
摘要:1.题目描述 Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any b...
阅读全文
摘要:1.题目描述 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; ...
阅读全文