摘要: 题目:Sort a linked list in O(n log n) time using constant space complexity.题解:考虑到要求用O(nlogn)的时间复杂度和constant space complexity来sort list,自然而然想到了merge sor... 阅读全文
posted @ 2014-07-26 02:51 爱做饭的小莹子 阅读(4473) 评论(0) 推荐(1) 编辑
摘要: 题目: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.F... 阅读全文
posted @ 2014-07-26 02:21 爱做饭的小莹子 阅读(2001) 评论(0) 推荐(0) 编辑
摘要: leetcode很多题目都是利用快慢指针来解决题目,下面具体讲解下快慢指针。概念: 快指针在每一步走的步长要比慢指针一步走的步长要多。快指针通常的步速是慢指针的2倍。在循环中的指针移动通常为:faster = faster.next.next, slower = slower.next.应用:1.... 阅读全文
posted @ 2014-07-26 02:05 爱做饭的小莹子 阅读(1227) 评论(0) 推荐(0) 编辑
摘要: 题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题解:Merge k sorted linked list就是merge 2 sorted li... 阅读全文
posted @ 2014-07-26 00:12 爱做饭的小莹子 阅读(4320) 评论(0) 推荐(1) 编辑
摘要: 题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k the... 阅读全文
posted @ 2014-07-24 04:31 爱做饭的小莹子 阅读(2918) 评论(0) 推荐(0) 编辑
摘要: 题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a sin... 阅读全文
posted @ 2014-07-24 03:58 爱做饭的小莹子 阅读(5903) 评论(0) 推荐(0) 编辑
摘要: 题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep c... 阅读全文
posted @ 2014-07-24 02:46 爱做饭的小莹子 阅读(4849) 评论(0) 推荐(0) 编辑
摘要: 题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2-... 阅读全文
posted @ 2014-07-24 00:54 爱做饭的小莹子 阅读(4806) 评论(0) 推荐(0) 编辑
摘要: 题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flatten... 阅读全文
posted @ 2014-07-24 00:08 爱做饭的小莹子 阅读(4814) 评论(0) 推荐(0) 编辑
摘要: 题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->... 阅读全文
posted @ 2014-07-23 23:37 爱做饭的小莹子 阅读(2827) 评论(0) 推荐(1) 编辑