04 2014 档案
摘要:原题地址:http://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/题意:Given a linked list, remove thenthnode from the end of list and return its he...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/swap-nodes-in-pairs/题意:将链表中的节点两两交换。Given1->2->3->4, you should return the list as2->1->4->3.解题思路:这题主要涉及到链表的操作,没什么...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/linked-list-cycle-ii/题意:如果链表中存在环路,找到环路的起点节点。解题思路:这道题有点意思。首先使用快慢指针技巧,如果fast指针和slow指针相遇,则说明链表存在环路。具体技巧参见上一篇http://w...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/linked-list-cycle/题意:判断链表中是否存在环路。解题思路:快慢指针技巧,slow指针和fast指针开始同时指向头结点head,fast每次走两步,slow每次走一步。如果链表不存在环,那么fast或者fast...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/lru-cache/题意:设计LRU Cache参考文献:http://blog.csdn.net/hexinuaa/article/details/6630384 这篇博文总结的很到位。 https://github...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/reorder-list/题意:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/insertion-sort-list/题意:对链表进行插入排序。解题思路:首先来对插入排序有一个直观的认识,来自维基百科。 代码循环部分图示:代码:class Solution:# @p...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/sort-list/题意:链表的排序。要求:时间复杂度O(nlogn),空间复杂度O(1)。解题思路:由于题目对时间复杂度和空间复杂度要求比较高,所以查看了各种解法,最好的解法就是归并排序,由于链表在归并操作时并不需要像数组的...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/3sum-closest/题意:数组中每三个元素进行求和,找出所有和中大小最接近target的和,并返回这个和与target之间的差值。解题思路:使用一个变量mindiff来监测和与target之间的差值,如果差值为0,直接返...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/4sum/题意:从数组中找到4个数,使它们的和为target。要求去重,可能有多组解,需要都找出来。解题思路:一开始想要像3Sum那样去解题,时间复杂度为O(N^3),可无论怎么写都是Time Limited Exceeded...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/3sum/题意:从一个数组中找到三个数,使这三个数的和为0。有可能存在多组解,也有可能存在重复的解,所以需要去重。比如:num=[-1,0,1,2,-1,-4];那么存在两组解:[[-1,0,1],[-1,-1,2]],解中的...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/two-sum/题意:找出数组numbers中的两个数,它们的和为给定的一个数target,并返回这两个数的索引,注意这里的索引不是数组下标,而是数组下标加1。比如numbers={2,7,11,17}; target=9。那...
阅读全文
摘要:原题地址:http://oj.leetcode.com/problems/implement-strstr/题意:实现字符串匹配函数,并返回一个指针,这个指针指向原字符串中第一次出现待匹配字符串的位置。如:haystack='aabbaa'; needle='bb'。如果使用python实现,则最后...
阅读全文
摘要:[leetcode]Word Ladder II @ Python原题地址:http://oj.leetcode.com/problems/word-ladder-ii/参考文献:http://blog.csdn.net/doc_sgl/article/details/13341405 ht...
阅读全文