题意:给定一棵二叉树,返回按层遍历的结果
思路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
题意:给定数字n,生成所有可能的n对括号的组合
思路:dfs暴力枚举
当左括号出现的次数 < n 的时候,可以选择放置新的左括号
当右括号出现的次数 < 左括号的次数的时候,可以选择放置新的右括号
递归函数:
void generateparenthesis(int n, int left, int right, vector& result)
表示将生成的所有可能的n对括号的组合放到result中,
其中,
s表示已生成的部分括号,
left表示当前的左括号数,
right表示当前的右括号...
分类:
其他好文 时间:
2014-05-15 13:21:12
阅读次数:
311
fcitx输入法支持:准备文件sublime-imfix.c:/*sublime-imfix.cUse
LD_PRELOAD to interpose some function to fix sublime input method support for
linux.By Cjacker Hua...
分类:
其他好文 时间:
2014-05-15 11:03:55
阅读次数:
244
How to use DISM to install a hotfix from within
WindowsJeff Hughes (CORE)15 Feb 2011 10:10 AM22Hello, my name is Emmers Presson.
I am a Support Escala...
题意:中序遍历
思路:采用递归实现。因为函数声明是返回一个vector,所以每个子树返回的是该子树的中序遍历的结果
按照 左、根、右的次序把根和左右子树的vector合并起来就可以了...
分类:
其他好文 时间:
2014-05-15 06:21:09
阅读次数:
255
class Solution {public: int
canCompleteCircuit(vector &gas, vector &cost) { int len = gas.size(); if
(len diff(len, 0); for (...
分类:
其他好文 时间:
2014-05-15 01:58:39
阅读次数:
358
水题。数字一共就9个,去掉1是用来显示标点的,剩下8个。
穷举一下map,然后有几个数字,就输出这几个数字的排列,是一个dfs嘛。
map num;
void allCombinations(string &digits, int start, int len, string &pres, vector &res){
if(len == digits.length()){
...
分类:
其他好文 时间:
2014-05-15 01:42:26
阅读次数:
264
【题目】
Implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype shoul...
分类:
其他好文 时间:
2014-05-14 21:36:52
阅读次数:
348
题目一:
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = "aab",
Return
[
...
分类:
其他好文 时间:
2014-05-14 15:10:01
阅读次数:
293
点击这里查看文章
有空试试~~~唉。。。
Ubuntu (Linux) on Atom Z3700 Series
ASUS Transformer Book T100 is particularly interesting platform, because
some guys at XDA developers forum have already installed Androi...
分类:
系统相关 时间:
2014-05-14 15:08:01
阅读次数:
547