摘要: ListNode* reverseBetween(ListNode* prev,ListNode* next)//reverse prev->next, last->prev之间的链表 { ListNode* last = prev->next; ListNode* cur = last->next; while(cur!=next) { last->next = cur->next; cur->next = prev->next; prev->next = ... 阅读全文
posted @ 2013-10-26 21:18 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 有个公式。假设集合为[1,2,3,4],求出第6个组合。第6个组合对应的下标为5(下标从0开始),我们首先求出5所对应的lehmer码(lehmer code的解释参考链接1):5/3! = 0 余55/2! = 2 余11/1! = 1 余00 (lehmer code最后一位总为0)所以所求lehmer码为02105 = 0*3!+2*2!+1*1!+0*0! (0210)当前集合对应的序列为1234接下来将lehmer码中的每个数字当做当前序列的下标,下标0对应的集合元素为1,当前序列变成234;下标2对应的集合元素为4,当前序列变成23;下标1对应的集合元素为3,当前序列变成2;下标0 阅读全文
posted @ 2013-10-26 17:53 summer_zhou 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 和minimum window string的原理一样。维护一个window vector findSubstring(string S, vector &L) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; if(S.empty()||L.empty()) return res; unordered_map dict; vector needed(... 阅读全文
posted @ 2013-10-26 16:24 summer_zhou 阅读(161) 评论(0) 推荐(0) 编辑
摘要: O(n)的解法。[i,j]维护一个window,当cnt==tlen时表示这是一个valid window. Incrementcntby one if hasFound[x] is less than or equal to needToFind[x]. Why? When the constraint is met (that is,countequals toT's size), we immediately advance begin pointer as far right as possible while maintaining the constraint.needed 阅读全文
posted @ 2013-10-26 13:46 summer_zhou 阅读(218) 评论(0) 推荐(0) 编辑