码迷,mamicode.com
首页 >  
搜索关键字:二叉树.binary tree    ( 18099个结果
[LeetCode] Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
分类:其他好文   时间:2014-06-12 18:32:00    阅读次数:222
二叉搜索树实现MAP
二叉搜索树的基本实现。 1 /* 2 Date: 2014-04-29 3 purpose: An implementation of MAP using binary search tree. 4 */ 5 6 #ifndef CUSTOMIZED_MAP_H 7 #define CUST...
分类:其他好文   时间:2014-06-12 15:59:38    阅读次数:404
[LeetCode] Binary Tree Preorder/Inorder/Postorder Traversal
前中后遍历 递归版 1 /* Recursive solution */ 2 class Solution { 3 public: 4 vector preorderTraversal(TreeNode *root) { 5 6 vector resul...
分类:其他好文   时间:2014-06-10 19:38:03    阅读次数:219
Binary Tree Preorder Traversal
第一次看到accept,心里有点小开心/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode...
分类:其他好文   时间:2014-06-10 11:53:41    阅读次数:241
【leetcode】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 / \ ...
分类:其他好文   时间:2014-06-10 11:51:42    阅读次数:213
【leetcode】Recover Binary Search Tree
问题: 给定的二叉查找树中,有两个节点不小心被调换了位置,现在需要将其修正,不改变树的结构。 分析: 二叉排序树的中序遍历是有序的,所以这个问题又是建立在中序遍历模板上的问题,所以我们可以对其进行中序遍历,并用一个pre指针指向当前遍历结果中的最后一个结点,即下次遍历前的前一个结点。然后就可以通过将当前结点与pre结点进行比较,来判断是否有序了。若乱序,就将这两个结点都放入到预先定义的容器中...
分类:其他好文   时间:2014-06-10 10:54:41    阅读次数:153
Leetcode OJ: Binary Tree Maximum Path Sum
Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the be...
分类:其他好文   时间:2014-06-10 10:42:58    阅读次数:203
手写BST插入查找删除
binary search\sort\find operations status InsertNode(Node* root, data x, Node* father) { if(root==NULL) { if(father==NULL) Tree empty; else { if(xdata) { father->left=new Node//inital l...
分类:其他好文   时间:2014-06-10 08:09:49    阅读次数:234
【leetcode】Convert Sorted List to Binary Search Tree
问题: 给定一个有序链表,生成对应的平衡二叉搜索树。 分析 见Convert Sorted Array to Binary Search Tree 实现: TreeNode *buildTree(ListNode* head, ListNode *end){ if(head == NULL || head == end) return NULL; ...
分类:其他好文   时间:2014-06-10 07:17:29    阅读次数:264
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!