摘要: 题目:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL... 阅读全文
posted @ 2016-01-19 22:41 很好玩 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 题目:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.思路... 阅读全文
posted @ 2016-01-19 21:40 很好玩 阅读(397) 评论(0) 推荐(0) 编辑
摘要: 题目:Sort a linked list inO(nlogn) time using constant space complexity.思路:nlogn的排序有快速排序、归并排序、堆排序。双向链表用快排比较适合,堆排序也可以用于链表,单向链表适合用归并排序。/** * Definition fo... 阅读全文
posted @ 2016-01-19 16:53 很好玩 阅读(942) 评论(0) 推荐(0) 编辑
摘要: 题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your al... 阅读全文
posted @ 2016-01-19 16:05 很好玩 阅读(247) 评论(0) 推荐(0) 编辑