码迷,mamicode.com
首页 >  
搜索关键字:binary tree paths    ( 24317个结果
Codeforces Round #245 (Div. 1)——Xor-tree
给一棵树n个节点,1为根节点。操作为,选定一个节点x,当前值取反,x的孙子,孙子的孙子。。。均取反 现在告诉初始时每个点的值和最后每个点的目标值,求操作次数最少时需要选择那些节点...
分类:其他好文   时间:2014-05-14 01:20:50    阅读次数:367
leetcode第一刷_Unique Paths II
接着上面的问题,如果这个矩阵中有阻塞的障碍,就不能用前面的那种组合数的方法了,因为很多位置实际上是没有路的嘛。 剩下的合理解法只有dp了。跟那个求最小和的非常像,从右下角往前推算,对于一个位置(i, j),它的走法应该是(i+1, j)和(i, j+1)走法的和。对于边界条件还是有一些特殊,最后一行,从右往左,如果是0的话没有问题,等于右侧走法的个数,一旦遇到一个1,那么它以及它左边的走法都必须...
分类:其他好文   时间:2014-05-14 01:00:13    阅读次数:305
Leetcode 树 Symmetric Tree
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Symmetric Tree  Total Accepted: 13991 Total Submissions: 44240 Given a binary tree, check whether it is a mirror of itself ...
分类:其他好文   时间:2014-05-14 00:52:07    阅读次数:372
leetcode第一刷_Unique Paths
从左上到右下,只能向右或向下,问一共有多少种走法。 这个问题当然可以用递归和dp来做,递归的问题是很可能会超时,dp的问题是需要额外空间。 其实没有其他限制条件的话,这个问题有个很简单的解法。给定一个格子,假设是m*n的,从左上角走到右下角的总步数是确定了的,(m+n-2)嘛,即在竖直方向一定要走m-1步,在水平方向一定要走n-1步。那有多少种解法就相当于确定什么时候往下走,什么时候往右走,也...
分类:其他好文   时间:2014-05-14 00:41:02    阅读次数:447
[leetcode]Binary Tree Level Order Traversal II @ Python
原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/题意:Given a binary tree, return thebottom-up level ordertraversal of its node...
分类:编程语言   时间:2014-05-12 22:03:27    阅读次数:581
[leetcode]Binary Tree Zigzag Level Order Traversal @ Python
原题地址:http://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/题意:Given a binary tree, return thezigzag level ordertraversal of its nod...
分类:编程语言   时间:2014-05-12 22:02:26    阅读次数:480
[leetcode]Minimum Depth of Binary Tree @ Python
原题地址:http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/题意:Given a binary tree, find its minimum depth.The minimum depth is the number of no...
分类:编程语言   时间:2014-05-12 21:55:15    阅读次数:348
boost::archive::binary_iarchive
#include #include #include #include #include #include #include #include #include #include using namespace std;struct MyStruct{ string stru; int ...
分类:其他好文   时间:2014-05-12 21:51:09    阅读次数:572
[leetcode]Convert Sorted Array to Binary Search Tree @ Python
原题地址:http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/题意:将一个排序好的数组转换为一颗二叉查找树,这颗二叉查找树要求是平衡的。解题思路:由于要求二叉查找树是平衡的。所以我们可以选在数组的中间那...
分类:编程语言   时间:2014-05-12 21:44:57    阅读次数:379
[leetcode]Convert Sorted List to Binary Search Tree @ Python
原题地址:http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/题意:将一条排序好的链表转换为二叉查找树,二叉查找树需要平衡。解题思路:两个思路:一,可以使用快慢指针来找到中间的那个节点,然后将这个节点作为...
分类:编程语言   时间:2014-05-12 21:07:00    阅读次数:405
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!