随笔分类 -  List

摘要:Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is a 阅读全文
posted @ 2016-07-10 23:04 北叶青藤 阅读(239) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example Given lists: [ 2->4->null, null, -1->null ] 阅读全文
posted @ 2016-07-06 07:22 北叶青藤 阅读(173) 评论(0) 推荐(0)
摘要:Swap Nodes | Given a linked list, swap every two adjacent nodes and return its head. Example Given 1->2->3->4, you should return the list as 2->1->4-> 阅读全文
posted @ 2016-07-05 12:24 北叶青藤 阅读(190) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it h 阅读全文
posted @ 2016-07-03 11:45 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要:Given a singly linked list L: L0 → L1 → … → Ln-1 → Ln reorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … Example Given 1->2->3->4->null, reorder it to 阅读全文
posted @ 2016-07-03 10:33 北叶青藤 阅读(174) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example Given 1->3->2->null, sort it to 1->2->3->null. Merge Sort version 1 /** 阅读全文
posted @ 2016-07-03 10:24 北叶青藤 阅读(185) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-07-03 08:03 北叶青藤 阅读(169) 评论(0) 推荐(0)
摘要:Reverse Linked List I Reverse a linked list. Example For linked list 1->2->3, the reversed linked list is 3->2->1 分析: 典型的3 pointers 问题。 1 /** 2 * Defi 阅读全文
posted @ 2016-07-03 07:32 北叶青藤 阅读(192) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-07-03 06:55 北叶青藤 阅读(178) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Example 2 1->2->3 => / \ 1 3 分析:非常简单,用递归 阅读全文
posted @ 2016-07-03 06:00 北叶青藤 阅读(251) 评论(0) 推荐(0)
摘要:Remove Duplicates from Sorted List I Given a sorted linked list, delete all duplicates such that each element appear only once. Remove Duplicates from 阅读全文
posted @ 2016-07-03 04:36 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要:Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the 阅读全文
posted @ 2016-07-03 04:22 北叶青藤 阅读(140) 评论(0) 推荐(0)
摘要:Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Find the nth to last element of a singly linked list. 阅读全文
posted @ 2016-07-03 03:51 北叶青藤 阅读(219) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. Given a list, rotate the list to the right by k places, where k is no 阅读全文
posted @ 2016-07-03 03:32 北叶青藤 阅读(143) 评论(0) 推荐(0)
摘要:Given a linked list, remove the nth node from the end of list and return its head. Notice The minimum number of nodes in list is n. Example Given link 阅读全文
posted @ 2016-07-03 02:34 北叶青藤 阅读(156) 评论(0) 推荐(0)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. Notice If the two linked lists have no intersection at a 阅读全文
posted @ 2016-07-03 02:12 北叶青藤 阅读(156) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort. Sort a linked list using insertion sort. Sort a linked list using insertion sort. Example Given 1->3->2->0->n 阅读全文
posted @ 2016-07-03 00:37 北叶青藤 阅读(132) 评论(0) 推荐(0)
摘要:Implement a function to check if a linked list is a palindrome. Implement a function to check if a linked list is a palindrome. Implement a function t 阅读全文
posted @ 2016-07-02 13:08 北叶青藤 阅读(200) 评论(0) 推荐(0)
摘要:Remove all elements from a linked list of integers that have value val. Example Given 1->2->3->3->4->5->3, val = 3, you should return the list as 1->2 阅读全文
posted @ 2016-07-02 11:24 北叶青藤 阅读(183) 评论(0) 推荐(0)
摘要:Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate value 阅读全文
posted @ 2016-07-02 11:06 北叶青藤 阅读(226) 评论(0) 推荐(0)