码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果)
leetcode[99] Recover Binary Search Tree
题目:二叉树中有两个节点对换了值,恢复他们。思路:因为中序遍历是有序的,如果中序遍历后的数组出现乱序,说明就是交换的。从前往后,第一次乱序的第一个,后最后一次乱序的后一个,然后把这两个值对换就好了。想了个非常挫的办法。先中序遍历Binary Tree Inorder Traversal,然后在数组中...
分类:其他好文   时间:2014-11-27 00:08:40    阅读次数:240
Slim Span
Description Given an undirected weighted graph G , you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E) , where V is a set of vertices {v1, v2...
分类:其他好文   时间:2014-11-26 22:45:41    阅读次数:364
LeetCode[String]: Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 我的C++实现代码如下: string addBinary(string a, string b) { string sum; int c...
分类:其他好文   时间:2014-11-26 22:43:30    阅读次数:196
[leetcode]
问题描述: Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 2 / 3 return [1,3,2]. Note: Recursive solution...
分类:其他好文   时间:2014-11-26 22:39:25    阅读次数:227
LeetCode Add Binary 两个二进制数相加
1 class Solution { 2 public: 3 string addBinary(string a, string b) { 4 if(a==""&&b=="") return ""; 5 if(a=="") return b; 6...
分类:其他好文   时间:2014-11-26 22:22:01    阅读次数:198
HDU 2841-Visible Trees(容斥原理)
题目链接:传送门 题意:有一个n*m的矩阵上布满了树(矩阵从(1,1)开始),现在有一个农夫站在(0,0)点,问农夫可以看到多少棵树,其中如果这些树在一条线上那么只能看到最前面的那棵树,这个一开始看到确实蒙了。。看了题解其实是挺简单的。首先考虑只能看到一条线上最前面的那棵树这个条件,对于坐标 比如 (2,3)(4,6)(6,9)。。等 这些坐标是在一条直线上的 可以看出其除了(2,3) 其他的都...
分类:其他好文   时间:2014-11-26 20:59:05    阅读次数:235
[LeetCode]Balanced Binary Tree
Given 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 subtrees of every node never diffe...
分类:其他好文   时间:2014-11-26 19:04:36    阅读次数:148
perl学习之路2
这些主要是从 "小骆驼" 书上粘贴或者摘抄出来的, 个人认为需要记的语法知识"在某些情况下, 你可能需要在一台机器上写程序, 再传送到另一台机器上运行.这时候, 请使用"文本模式(text mode)" 或者"ASCII模式(ASCIImode)". 记住, 千万不能是"二进制模式(binary m...
分类:其他好文   时间:2014-11-26 18:32:09    阅读次数:166
LeetCode - Convert Sorted Array to Binary Search Tree
给出一个已排序的数组,将其转化为二叉查找树(BST)。思路:取数组中间元素为根结点的value,则数组左侧、右侧分别为BST的左子树、右子树。递归可求解。代码如下: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * ...
分类:其他好文   时间:2014-11-26 18:13:30    阅读次数:206
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
分类:其他好文   时间:2014-11-26 13:58:49    阅读次数:255
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!