随笔分类 -  链表

摘要:不知道为什么,现在某些公司喜欢考单链表快排,有什么意思呢?没意思。首先理解快排的思想,partition,递归。代码里有注释,挺详细的了,自己验证逻辑应该没什么问题。package leetcode.sort;import java.io.FileInputStream;import java.io... 阅读全文
posted @ 2015-11-04 13:20 丶Blank 阅读(1357) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2015-06-07 22:35 丶Blank 阅读(152) 评论(0) 推荐(0)
摘要:Sort a linked list inO(nlogn) time using constant space complexity.链表排序,要求时间复杂度O(nlgn),我写的归并排序。/** * Definition for singly-linked list. * public class... 阅读全文
posted @ 2015-06-07 16:52 丶Blank 阅读(141) 评论(0) 推荐(0)
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文
posted @ 2015-05-25 17:07 丶Blank 阅读(201) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort.题目大意:将一个单链表使用插入排序的方式排序。解题思路:先新建一个头指针,然后重新构建一下这个单链表,每次从头找到第一个比当前元素大的,插在这个元素前面。/** * Definition for singly-linke... 阅读全文
posted @ 2015-05-24 19:23 丶Blank 阅读(105) 评论(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 @ 2015-05-20 13:49 丶Blank 阅读(129) 评论(0) 推荐(0)
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文
posted @ 2015-04-23 12:54 丶Blank 阅读(137) 评论(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 algor... 阅读全文
posted @ 2015-04-22 16:27 丶Blank 阅读(145) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题目大意:给定一个链表,判断是否有环?解题思路:解法一:快慢指针,如果有环,那么快慢... 阅读全文
posted @ 2015-04-22 10:33 丶Blank 阅读(173) 评论(0) 推荐(0)
摘要: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.No... 阅读全文
posted @ 2015-04-05 11:22 丶Blank 阅读(125) 评论(0) 推荐(0)