摘要: bool isValidBST(TreeNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. return helper(root,INT_MIN,INT_MAX); } bool helper(TreeNode* root,int lower,int upper) { if(!root) return true; if... 阅读全文
posted @ 2013-10-03 23:26 summer_zhou 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Two pointers问题。留心一个问题,num.size()返回的是无符号数。当其值为1,i==0时,i > threeSum(vector &num) { // Start typing your C/C++ solution below // DO NOT write int main() function vector> res; if(num.empty()) return res; sort(num.begin(),num.end()); int i,j,k; ... 阅读全文
posted @ 2013-10-03 23:12 summer_zhou 阅读(137) 评论(0) 推荐(0) 编辑
摘要: A: 二分Maintaining the invarianti+j=k– 1,If Bj-1= 0); assert(n >= 0); assert(k > 0); assert(k = 0); assert(j >= 0); assert(i Bj && Ai_1 > Bj) || (Ai < Bj && Ai < Bj_1)); // if none of the cases above, then it is either: if (Ai < Bj) // exclude Ai and below portion 阅读全文
posted @ 2013-10-03 19:04 summer_zhou 阅读(474) 评论(0) 推荐(0) 编辑
摘要: int lengthOfLongestSubstring(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. int max_len = 0,cur_len = 0; int hash[256]; for(int i=0;i<256;i++) hash[i] = -1; for(int i=0;i<s.size();i... 阅读全文
posted @ 2013-10-03 10:28 summer_zhou 阅读(132) 评论(0) 推荐(0) 编辑