Linked List
文章平均质量分 59
NoooName
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[Leetcode]Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2014-12-15 23:19:25 · 350 阅读 · 0 评论 -
[Leetcode]Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序的链表~brute force的方法是把这k个链表一个一个的合并起来,如 k个链表为[l1, l2, l3, l4],可以先合并l1, l2,再把合并得到的链表与l3合并,最后再与原创 2015-03-19 08:05:25 · 364 阅读 · 0 评论 -
[Leetcode]Rotate List
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->3->NULL.链表右移k个节点~ 因为k可能超过链表的长度,所以记得对其进行取余原创 2015-01-01 19:51:41 · 317 阅读 · 0 评论 -
[Leetcode]Reorder List
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.For example,Given {1,2,3,4}, reorder it t原创 2015-02-08 17:14:49 · 367 阅读 · 0 评论 -
[Leetcode]Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-12-15 22:21:32 · 333 阅读 · 0 评论 -
[Leetcode]Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.比较简单的一道链表题~ 把两个排序得链表merge~ 时间复杂度是O(m+n),(m, n 分别是两个list原创 2014-12-15 16:50:57 · 305 阅读 · 0 评论 -
[Leetcode]Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->原创 2014-12-30 20:04:14 · 445 阅读 · 0 评论 -
[Leetcode]Reverse Nodes in k-Group
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 then left-out nodes in the end should remain as it is原创 2014-12-30 13:38:36 · 317 阅读 · 0 评论 -
[Leetcode]Add Two Numbers
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 single digit. Add the two numbers and return it as a link原创 2014-12-31 14:32:17 · 358 阅读 · 0 评论 -
[Leetcode]Sort List
Sort a linked list in O(n log n) time using constant space complexity.链表排序~可以用merge sort~找到链表的中点,然后对左右进行递归,最后再把两段lists合并~Merge Sort的时间复杂度为O(nlogn)~class Solution: # @param head, a ListNode原创 2015-02-05 20:22:40 · 330 阅读 · 0 评论 -
[Leetcode]Insertion Sort List
Sort a linked list using insertion sort.在链表上实现插入排序~ 插入排序就是每次循环把一个元素插入到当前排好的结果中相对应的位置,经过n次迭代之后就得到排好序的结果,时间复杂度为O(n^2)~ 自己写的TLE(超时)了,看到也有很多人反映同样的代码,用python写会超时,用java就accept了~ 参照了网上的python代码,accep原创 2014-12-29 14:24:55 · 379 阅读 · 0 评论 -
[Leetcode]Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-12-25 14:30:07 · 296 阅读 · 0 评论 -
[Leetcode]Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?Linked List Cycle的扩展题,要找到cycle的起始点,还是跟Link原创 2014-12-16 15:27:50 · 361 阅读 · 0 评论 -
[Leetcode]Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.把一个有序的链表转换成一颗二分查找树 ~ 刚开始用了一种比较naive的写法,虽然能AC,但是效率很慢,因为每次递归的时候都要遍历链表获得中间节点 ~ 时间复杂度是O(Nlo原创 2014-12-17 11:20:02 · 396 阅读 · 0 评论 -
[Leetcode]Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-12-17 09:40:33 · 405 阅读 · 0 评论 -
[Leetcode]Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.基础链表题~ 把重复得节点去掉~ 维护了两个原创 2014-12-15 22:53:58 · 343 阅读 · 0 评论 -
[Leetcode]Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?比较常见的一道题 cracking code interview上也有~ 判断链表里有没有cycle 常见的方法是维护两个指针slow和fast,两个指针以原创 2014-12-16 14:59:28 · 320 阅读 · 0 评论 -
[Leetcode]Reverse Linked List II
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->2->5->NULL.Note:Given m, n satisfy the原创 2014-12-16 14:13:35 · 367 阅读 · 0 评论 -
[Leetcode]Copy List with Random Pointer
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 copy of the list.链表的每个节点都有一个random的指针,可以指向链表中的任原创 2014-12-31 13:14:41 · 309 阅读 · 0 评论
分享