摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".注意考虑有多个空格的情况就好了,选择的处理办法是在进行空格查找之前先整理字符串 1 #include 2 #include 3 using namespace std; 4 class Solution { 5 public: 6 void reverseWords(string &s) { 7 checkSt 阅读全文
posted @ 2014-03-08 15:50 青轰的后花园 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmented as"leet code&quo 阅读全文
posted @ 2014-03-07 16:11 青轰的后花园 阅读(319) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-03-07 09:27 青轰的后花园 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?2种解法,一种是正常递归,另一种是使用栈思想 1 #include 2 #include 3 #include 4 using namespace std; 5 struct... 阅读全文
posted @ 2014-03-06 20:20 青轰的后花园 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 跟着Binary Tree Level Order TraversalBinary Tree Level Order Traversal II这两题做下来基本AC没什么难度,题还是连着做顺手。/*** Definition for binary tree* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/#include #include using namespace... 阅读全文
posted @ 2014-03-06 16:19 青轰的后花园 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]思想:链表按层遍历,总体感觉类似多线程在遍历文件时获得文件夹的过程,对于每一层,只获... 阅读全文
posted @ 2014-03-06 15:55 青轰的后花园 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.思想主要是使用递归,获得节点左枝和右枝的最大值,然后和自己的值相加,如果大于最大值则替换。同时要注意的是:如果该节点有父节点,那么只能返回self.val+left.val或者self.val+right.val.详细参考:http://www.cnbl... 阅读全文
posted @ 2014-03-06 11:02 青轰的后花园 阅读(147) 评论(0) 推荐(0) 编辑
摘要: RT。 阅读全文
posted @ 2013-02-27 14:12 青轰的后花园 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 论坛看到的好帖子(网摘http://bbs.byr.cn/#!article/CPP/55608)关于顺时螺旋法则的实践,以前这种很复杂的函数总是很难下手去解,试了螺旋法则是要容易不少。下面是一些实践用的理解的例子。char (*(*x())[])()1.x是一个参数为空的,返回值为指向一个指向参数为空,返回值为char类型的函数指针的数组指针函数。int (*func)(int *p); func是一个指向参数为int型指针,返回值为int类型的函数的指针。int (*func) (int *p, int(*f)(int *))func 是一个指向 一个参数为int型指针,另一个参数为……, 阅读全文
posted @ 2012-10-23 11:11 青轰的后花园 阅读(338) 评论(0) 推荐(0) 编辑
摘要: 自动化测试大概可以分为 单元划分->程序改造->建立测试框架->测试用例执行管理->测试用例自动生成。其中单元划分-将给出的测试代码根据函数划分为不同的子单元以方便测试 可以分为 1.自动单元划分 2.人工干预 tip:自动化单元划分中会把每个函数都划分为一个单元,而人工干预则可以将某几个关联较为密切的函数划分在同一个单元之中,这样可以有效减少打桩的工作量,比自动划分更有效率. 程序改造-为了使测试代码可以跑起来需要对源测试代码在不损害其源代码逻辑基础上进行改造 主要包括 1.重命名main()函数 这个很好理解,如果测试函数中已经有main函数了的话,就需要将其重命名 阅读全文
posted @ 2012-09-14 21:01 青轰的后花园 阅读(437) 评论(0) 推荐(0) 编辑