Tree
benbenab
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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.class Solution {public: TreeNode *buildTree(vector原创 2012-11-02 09:58:06 · 2052 阅读 · 0 评论 -
Unique Binary Search Trees
Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that store values 1...n?class Solution {public: int numTrees(int n) { // Star原创 2012-12-11 05:35:43 · 444 阅读 · 0 评论 -
[leetcode] BST与链表的相互转换
1. 链表-->BST (借鉴smile的)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition原创 2012-12-31 12:17:10 · 1518 阅读 · 0 评论 -
[leetcode] 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 / \ 2 3Return 6.原创 2012-12-28 09:59:48 · 372 阅读 · 0 评论 -
找出一个bst中第二大的数
search the most right node from root. If the most right root has no child, return its parent; otherwise return the largest number of its left child tree转载 2012-12-22 09:33:07 · 804 阅读 · 0 评论 -
把二叉树转换为双向链表
void convert(TreeNode* root,TreeNode** preNode,TreeNode** head){ if (root==NULL) return; convert(root->left,preNode,head); if (*preNode!= NULL){ root->left = *preNode; (*preNode)->right = ro原创 2012-11-25 09:56:41 · 524 阅读 · 0 评论 -
binary tree path add
要求路径可以从任何位置开始void checkPath(int sum,vector result,vector>& results ){ vector resultTemp; for(int i = result.size()-1;i>=0;i--){ sum -= result.at(i)->val; resultTemp.insert(resultTemp.begin()原创 2012-12-05 05:25:40 · 443 阅读 · 0 评论 -
Symmetric Tree
Given 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 3But the f原创 2012-11-14 10:51:45 · 310 阅读 · 0 评论 -
给定后序遍历和前序遍历,不同的树有多少种
假设一棵树的每个node都有不同的标号,给定后序遍历和前序遍历,不同的树有多少种?思路:给定中序遍历能确定树的具体结构,是因为可以确定到底是左子树还是右子树,而之给定preorder和pastorder,则不能确定,这也是为什么会出现不同树结构的原因。只有 post 和 pre 那么主要问题就是没有办法处理只有一个subtree的 node,因为 这种情况 不知道subtree 究竟是这个原创 2012-11-02 10:07:42 · 2214 阅读 · 0 评论 -
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-09-29 14:49:40 · 605 阅读 · 0 评论
分享