随笔分类 -  list

1

[leecode]Word Break II
摘要:Word Break IIGiven a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all... 阅读全文

posted @ 2014-08-24 22:49 喵星人与汪星人 阅读(283) 评论(0) 推荐(0) 编辑

快速排序之单项扫描法
摘要:快速排序是排序算法中最受青睐的算法之一,相对于堆排序和归并排序而言,即便具有相同的复杂度O(NlogN)。面对大数据而言,快排的效率也更高。一般而言,数据结构中的排序算法都是采取的双向指针法。在之前写的一篇博文《排序算法(初级版)之快排、归并、堆排序》中已经有过总结。这里就不再啰嗦了。本篇博文主要讲... 阅读全文

posted @ 2014-08-22 17:00 喵星人与汪星人 阅读(1785) 评论(0) 推荐(0) 编辑

[leetcode]Best Time to Buy and Sell Stock II
摘要:Best Time to Buy and Sell Stock IISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the ... 阅读全文

posted @ 2014-08-06 22:58 喵星人与汪星人 阅读(197) 评论(0) 推荐(0) 编辑

[leetcode]Copy List with Random Pointer
摘要:Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the lis... 阅读全文

posted @ 2014-08-06 15:42 喵星人与汪星人 阅读(125) 评论(0) 推荐(0) 编辑

[leetcode]Add Two Numbers
摘要:Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes co... 阅读全文

posted @ 2014-07-23 16:17 喵星人与汪星人 阅读(240) 评论(0) 推荐(0) 编辑

[leetcode]Sort List
摘要:Sort ListSort a linked list inO(nlogn) time using constant space complexity.算法思想:时间复杂度为O(nlogn)的排序算法,有快排、归并、堆排序,快排需要往前遍历,因此不适合单链表,堆排序可以,但是需要O(n)的空间,因此... 阅读全文

posted @ 2014-07-21 22:33 喵星人与汪星人 阅读(258) 评论(0) 推荐(0) 编辑

[leetcode]Reverse Linked List II
摘要:Reverse Linked List IIReverse 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,return... 阅读全文

posted @ 2014-07-21 21:19 喵星人与汪星人 阅读(183) 评论(0) 推荐(0) 编辑

[leetcode]Reverse Nodes in k-Group
摘要:Reverse Nodes in k-GroupGiven a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a... 阅读全文

posted @ 2014-07-21 20:23 喵星人与汪星人 阅读(307) 评论(0) 推荐(0) 编辑

[leetcode]Reorder List
摘要:Reorder ListGiven a singly linked listL: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' val... 阅读全文

posted @ 2014-07-21 15:13 喵星人与汪星人 阅读(277) 评论(0) 推荐(0) 编辑

[leetcode]Insertion Sort List
摘要:Insertion Sort ListSort a linked list using insertion sort.算法思路:最基本的插入排序,时间复杂度O(n*n),空间复杂度O(1)代码: 1 public class Solution { 2 public ListNode inse... 阅读全文

posted @ 2014-07-21 14:50 喵星人与汪星人 阅读(171) 评论(0) 推荐(0) 编辑

[leetcode]Partition List
摘要:Partition ListGiven a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should pres... 阅读全文

posted @ 2014-07-20 17:07 喵星人与汪星人 阅读(172) 评论(0) 推荐(0) 编辑

[leetcode]Remove Duplicates from Sorted List II
摘要:Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the or... 阅读全文

posted @ 2014-07-20 15:14 喵星人与汪星人 阅读(186) 评论(0) 推荐(0) 编辑

[leetcode]Remove Duplicates from Sorted List
摘要:Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, r... 阅读全文

posted @ 2014-07-20 14:49 喵星人与汪星人 阅读(191) 评论(0) 推荐(0) 编辑

[leetcode]Merge k Sorted Lists
摘要:Merge k Sorted ListsMergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.这道题,第一次刷是过了,第二次同样的代码超时了,看来case是在不断... 阅读全文

posted @ 2014-07-20 01:18 喵星人与汪星人 阅读(280) 评论(0) 推荐(0) 编辑

[leetcode]Merge Two Sorted Lists
摘要:Merge Two Sorted ListsMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the fir... 阅读全文

posted @ 2014-07-19 18:05 喵星人与汪星人 阅读(292) 评论(0) 推荐(0) 编辑

[leetcode]Rotate List
摘要:Rotate ListGiven 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-... 阅读全文

posted @ 2014-07-19 17:35 喵星人与汪星人 阅读(167) 评论(0) 推荐(0) 编辑

[leetcode]Swap Nodes in Pairs
摘要:Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2-... 阅读全文

posted @ 2014-07-19 16:32 喵星人与汪星人 阅读(224) 评论(0) 推荐(0) 编辑

[leetcode]Remove Nth Node From End of List
摘要:Remove Nth Node From End of ListGiven a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2... 阅读全文

posted @ 2014-07-19 16:03 喵星人与汪星人 阅读(217) 评论(0) 推荐(0) 编辑

[leetcode]Linked List Cycle II
摘要:Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without u... 阅读全文

posted @ 2014-07-19 15:36 喵星人与汪星人 阅读(215) 评论(0) 推荐(0) 编辑

[leetcode]Linked List Cycle
摘要:Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?算法思路1:快慢指针,当两个指针相遇,则表示有环,... 阅读全文

posted @ 2014-07-19 14:59 喵星人与汪星人 阅读(293) 评论(0) 推荐(0) 编辑

1