上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 31 下一页
  2012年12月18日
摘要: #include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};/*本题心得:0 如何分析一个问题1 没有固定格式的判断方式2 越界*/class Solution {public: int maxPathSum 阅读全文
posted @ 2012-12-18 23:48 kkmm 阅读(868) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;class Solution {public: string countAndSay(int n) {//调用process N次 if (n<1) return ""; string str = "1"; if (n == 1) return str; for (int i = 1; i < n; i++){ ... 阅读全文
posted @ 2012-12-18 23:47 kkmm 阅读(1098) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;void QuickSortCore(int a[], int start, int end){ if (start > end) return; int key = a[start]; int blank = start; int left = start + 1; int right = end; while(left <= right){//维护left right blank key if (blank < left){ i... 阅读全文
posted @ 2012-12-18 23:46 kkmm 阅读(180) 评论(0) 推荐(0) 编辑
  2012年12月17日
摘要: #include <iostream>#include <vector>using namespace std;struct BTreeNode{ int value; BTreeNode *lchild; BTreeNode *rchild;};bool IsBalanced(BTreeNode *pRoot, int &height){ if (!pRoot){ height = 0; return true; } int leftHeight = 0; int rightHeight = 0; bool left... 阅读全文
posted @ 2012-12-17 14:11 kkmm 阅读(349) 评论(0) 推荐(0) 编辑
  2012年12月15日
摘要: 转自:http://blog.csdn.net/shuchao/article/details/3705252调用reverse_iterator的base成员函数可以产生“对应的”iterator,但这句话有些辞不达意。举个例子,看一下这段代码,我们首先把从数字1-5放进一个vector中,然后产生一个指向3的reverse_iterator,并且通过reverse_iterator的base初始化一个iterator:vector<int> v;v.reserve(5); // 参见条款14for(int i = 1;i <= 5; ++ i) { // 向vector插 阅读全文
posted @ 2012-12-15 20:13 kkmm 阅读(2440) 评论(0) 推荐(0) 编辑
摘要: 转自:http://blog.csdn.net/kjing/article/details/6936325rbegin和rend,很有用!C++ primer (中文版第四版)第273页9.3.2 begin和end成员 begin和end操作产生指向容器内第一个元素和最后一个元素的下一个位置的迭代器,如下所示。这两个迭代器通常用于标记包含容器中所有元素的迭代范围。c.begin() 返回一个迭代器,它指向容器c的第一个元素c.end() 返回一个迭代器,它指向容器c的最后一个元素的下一个位置c.rbegin() 返回一个逆序迭代器,它指向容器c的最后一个元素c.rend() 返回一个逆序迭代 阅读全文
posted @ 2012-12-15 20:01 kkmm 阅读(4419) 评论(0) 推荐(1) 编辑
  2012年12月14日
摘要: #include <iostream>#include <stack>#include <string>using namespace std;//merge a b两个排序过的数组,a的size是m,b的size是n,a具有足够大的空间存放merge后的元素们//思想是从后往前merge,因为后面都是没有存放数的空间,所以可以避免数组的平移void Merge(int a[], int b[], int m, int n){ int mWalker = m-1; int nWalker = n-1; for (int i = m+n-1 ; i > 阅读全文
posted @ 2012-12-14 16:29 kkmm 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Imagine a (literal) stack of plates If the stack gets too high, it might topple There-fore, in real life, we would likely start a new stack when the previous stack exceeds some threshold Implement a data structure SetOfStacks that mimics this SetOf-Stacks should be composed of several stacks, and sh 阅读全文
posted @ 2012-12-14 16:14 kkmm 阅读(716) 评论(0) 推荐(0) 编辑
摘要: 本方法借鉴自glibc,可以过滤如下情况:前缀空格非法输入正负号16进制8进制溢出1234L#include <iostream>using namespace std;#define LONG_MAX 2147483647L#define LONG_MIN -2147483648Llong StrToInt(const string &str){ unsigned long result = 0;//如果不用unsigned long,那么后面无法判断溢出(当发生溢出时,总是负数) int radix = 0; int sign = 1; string::const_.. 阅读全文
posted @ 2012-12-14 14:46 kkmm 阅读(244) 评论(0) 推荐(0) 编辑
  2012年12月13日
摘要: 程序设计中经常会出现这样的场景:遍历一个字符串a(例如:“A dog in on the floor.”),对于字符串b(例如“dnr”)中出现过的字符,统统删掉。那么对于b中出现的字符,通常可以保存在bool label[256]中来记录某个字符是否在字符串b中。但是还可以用一种更省内存的方式,就是bitmap。通过定义Set,ReSet和Get宏来快速定位某一个bit。并且使用sizeof(int)和动态数组来适应64位平台。#include <iostream>using namespace std;int intWidth = sizeof(int) * 8;int *la 阅读全文
posted @ 2012-12-13 14:34 kkmm 阅读(343) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 31 下一页