2012年12月8日
摘要: 解法思想见原题:http://www.leetcode.com/2011/05/longest-substring-without-repeating-characters.html#include <iostream>#include <algorithm>#include <string>#include <vector>using namespace std;/* LeetCode: Longest Substring Without Repeating Charactersreturn value: length of longest s 阅读全文
posted @ 2012-12-08 23:17 kkmm 阅读(286) 评论(0) 推荐(0) 编辑
摘要: 算法思想借鉴自:http://blog.csdn.net/clamreason/article/details/7904062由2个元素开始作为初始条件,一个一个元素的添加进现有数组,保存2个变量,1个是currMin,就是当前处理的子数组的最小元素,一个是maxDiff,就是当前处理的子数组中最大的数对之差。如果当前添加的元素比min小,更新min,如果当前添加的元素减去min比maxDiff大,那么更新maxDiff。/* LeetCode: A Distance Maximizing Problemreturn value: max differenceparameters: arr - 阅读全文
posted @ 2012-12-08 22:52 kkmm 阅读(562) 评论(0) 推荐(0) 编辑
摘要: struct Node{ int value; Node *pLeft; Node *pRight; Node *pParent;};//BTree(not a BST)//both has parent pointerNode *LCA(Node *p, Node *q) //这里的p q为NULL的检测融入到了代码当中{ int pDepth = 0; int qDepth = 0; Node *walker = p; while (!walker) { walker = walker... 阅读全文
posted @ 2012-12-08 19:10 kkmm 阅读(190) 评论(0) 推荐(0) 编辑
摘要: //down-up approach for normal BTree(not a BST)//there's no parent pointerNode *LCA(Node *pRoot, Node *p, Node *q){ if (!pRoot) return NULL; if (pRoot == p || pRoot == q) return pRoot; Node *L = LCA(pRoot->pLeft, p, q); Node *R = LCA(pRoot->pRight, p, q); if (L && R) ... 阅读全文
posted @ 2012-12-08 17:51 kkmm 阅读(165) 评论(0) 推荐(0) 编辑