摘要: 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 @ 2014-10-26 10:21 Craze_lee 阅读(101) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.链表排序。要达到nlogn的时间复杂度,能想到归并排序与快速排序。这里采用归并排序: 1 /** 2 * Definition for singly-linked ... 阅读全文
posted @ 2014-10-26 09:30 Craze_lee 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Determine whether an integer is a palindrome. Do this without extra space.自己之前的想法是先转换成字符串模式,然后首尾同时开始遍历比较,如果不同则非回文。但是这个要求是不能有额外的空间。所以在网上查找了其他算法,看到是太惊叹了... 阅读全文
posted @ 2014-10-21 11:06 Craze_lee 阅读(246) 评论(0) 推荐(0) 编辑