摘要: Sort a linked list using insertion sort.思路: 建立一个fake head, 依次从list中取出一个node,插入到 fake head 的list中去,从小到大排列。public class Solution { public ListNode insertionSortList(ListNode head) { ListNode prehead = new ListNode(Integer.MIN_VALUE); ListNode runner = head; while(runner != null... 阅读全文
posted @ 2014-02-19 15:47 Razer.Lu 阅读(159) 评论(0) 推荐(0)
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文
posted @ 2014-02-19 09:57 Razer.Lu 阅读(267) 评论(0) 推荐(0)
摘要: 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 in-place without altering the nodes' values.For exam... 阅读全文
posted @ 2014-02-19 09:01 Razer.Lu 阅读(140) 评论(0) 推荐(0)
摘要: Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens="catsanddog",dict=["cat", "cats", "and", "sand", "dog"].A 阅读全文
posted @ 2014-02-19 08:12 Razer.Lu 阅读(172) 评论(0) 推荐(0)
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmented as"leet code&quo 阅读全文
posted @ 2014-02-19 02:18 Razer.Lu 阅读(340) 评论(0) 推荐(0)