上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 28 下一页
摘要: Sort a linked list in O(n log n) time using constant space complexity.解题思路:归并排序、快速排序、堆排序都是O(n log n),由于优先级队列是用堆排序实现的,因此,我们使用优先级队列即可,JAVA实现如下: publi... 阅读全文
posted @ 2015-06-04 22:29 TonyLuis 阅读(189) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort.解题思路:插入排序,JAVA实现如下: public ListNode insertionSortList(ListNode head) { if(head==null||head.next==null) ... 阅读全文
posted @ 2015-06-04 22:06 TonyLuis 阅读(317) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the... 阅读全文
posted @ 2015-06-04 21:49 TonyLuis 阅读(258) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,... 阅读全文
posted @ 2015-06-04 21:27 TonyLuis 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3... 阅读全文
posted @ 2015-06-04 21:19 TonyLuis 阅读(202) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list L: 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 ... 阅读全文
posted @ 2015-06-04 20:53 TonyLuis 阅读(277) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up:Can you solve it without using extra space?解... 阅读全文
posted @ 2015-06-04 20:34 TonyLuis 阅读(168) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?解题思路:由于不让用extra space,所以用一个快指针和一个慢指针,快指针一... 阅读全文
posted @ 2015-06-04 18:47 TonyLuis 阅读(220) 评论(0) 推荐(0) 编辑
摘要: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such po... 阅读全文
posted @ 2015-06-04 11:29 TonyLuis 阅读(486) 评论(0) 推荐(0) 编辑
摘要: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For e... 阅读全文
posted @ 2015-06-04 10:41 TonyLuis 阅读(322) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 28 下一页