题意:给定一棵二叉树,返回按层遍历的结果
思路1:bfs,定义一个新的struct,记录指针向节点的指针和每个节点所在的层
复杂度1:时间O(n),空间O(n)
思路2:dfs
递归函数:
void levelOrder(TreeNode *root, int level, vector<vector >&result)
表示把根为root的树按层存放在result中,其中level表示当前的层数
复杂度2:时间O(n),空间O(n)
相关题目:...
分类:
其他好文 时间:
2014-05-15 14:46:06
阅读次数:
355
Problem Description:
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys l...
分类:
其他好文 时间:
2014-05-15 11:22:21
阅读次数:
317
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Unique Binary Search Trees II
Total Accepted: 7349 Total
Submissions: 27648
Given n, generate all structurally unique ...
分类:
其他好文 时间:
2014-05-15 07:02:36
阅读次数:
252
题意:中序遍历
思路:采用递归实现。因为函数声明是返回一个vector,所以每个子树返回的是该子树的中序遍历的结果
按照 左、根、右的次序把根和左右子树的vector合并起来就可以了...
分类:
其他好文 时间:
2014-05-15 06:21:09
阅读次数:
255
1、
??
Populating Next Right Pointers in Each Node
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate...
分类:
其他好文 时间:
2014-05-15 04:57:36
阅读次数:
221
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Binary Tree Preorder Traversal
Total Accepted: 17948 Total
Submissions: 51578
Given a binary tree, return the preorder tra...
分类:
其他好文 时间:
2014-05-15 04:37:26
阅读次数:
283
安排任务的问题。
思路:
因为分报告时间和实际执行任务时间,这里要做的就是尽量使得报告时间和实际执行任务的时间重合,并行,那么就可以减小总时间。
原题:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2829
0.012s的算法,达到网站最高纪录。
...
分类:
其他好文 时间:
2014-05-15 04:23:35
阅读次数:
269
Same Tree
Total Accepted: 16072 Total
Submissions: 38790My Submissions
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal i...
分类:
其他好文 时间:
2014-05-15 04:00:39
阅读次数:
319
1.JavaEE5API(含JSFAPI)http://java.sun.com/javaee/5/docs/api/2.HibernateAPIDocumentation(3.2.2.ga)http://www.hibernate.org/hib_docs/v3/api/3.SpringFrameworkAPI2.5http://static.springframework.org/spring/docs/2.5.x/api/index.html4.1Struts1.3.8APIhttp://struts..
分类:
编程语言 时间:
2014-05-14 16:51:34
阅读次数:
407
staticint_osip_message_parse(osip_message_t*sip,constchar*buf,size_tlength,intsipfrag){inti;constchar*next_header_index;char*tmp;char*beg;tmp=osip_malloc(length+2);if(tmp==NULL){OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"Couldnotallocatememory..
分类:
其他好文 时间:
2014-05-14 16:06:25
阅读次数:
296