
LinkedList
文章平均质量分 77
ljffdream
这个作者很懒,什么都没留下…
展开
-
【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.【思路】这道题目就和array不一样,因为是linkedlist所以,不能随意访问到中间的元素,那么就只能一步一步从头开始顺序访问,从列表到BST,我们能感受到构原创 2014-11-26 12:59:59 · 314 阅读 · 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.【思路】实质就是n-k个元素挪到了链子的前面, 第原创 2015-07-29 23:06:14 · 261 阅读 · 0 评论 -
【Leetcode】Panlidrome Linked List
【题目】Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?【思路】panlidrome的话,回文,就是前后是一样的。第一个和最后一个一样, 第二个和倒数第二个一样。linked list转载 2015-07-17 11:27:36 · 332 阅读 · 0 评论 -
【Leetcode】Merge K Sorted Linked List
【题目】Merge k sorted Linked Lists and return it as one sorted lists. Analyze and describe its complexity .【思路】leetcode clean book【代码】 private static final Comparator listComparator = new转载 2015-07-16 21:39:48 · 369 阅读 · 0 评论 -
【Leetcode】Lowest common treenode in binary tree
【题目】Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between tw转载 2015-07-28 22:41:59 · 491 阅读 · 0 评论 -
【Leetcode】Sort List in O(nlogn) O(1)space
【题目】【思路】First of all, allow me to explain the meaning of strict O(1) auxiliary space complexity.It means the maximum number of memory used by the program, except the memory taken by th转载 2015-07-27 20:42:43 · 321 阅读 · 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转载 2015-06-14 13:02:44 · 290 阅读 · 0 评论 -
[Leetcode]Word Ladder
[题目]Given two words (beginWord and endWord), and a dictionary, find the length ofshortest transformation sequence frombeginWord to endWord, such that:Only one letter can be changed at a ti转载 2015-07-06 09:12:15 · 480 阅读 · 0 评论 -
【Leetcode】Delete Node in a LinkedList
【题目】Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node转载 2015-07-26 16:47:59 · 298 阅读 · 0 评论 -
【Leetcode】Reversed Linked List
【题目】 Reverse a singly linked list.click to show more hints.Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?【思路】 我自己想的办法就是可以用一个stack,先把每一个元素都装进去转载 2015-06-29 00:09:58 · 323 阅读 · 0 评论 -
[Leetcode]Remove Linked List Elements
[题目]Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special th原创 2015-07-01 09:41:30 · 329 阅读 · 0 评论 -
【Leetcode】Intersection of Two Linked List
【题目】: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 ↘原创 2015-03-30 13:18:51 · 366 阅读 · 0 评论 -
【Leetcode】 Intersection of two linked list
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 ↘原创 2015-03-30 13:48:16 · 414 阅读 · 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原创 2015-01-03 11:53:30 · 399 阅读 · 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?【分析】使用two pointer的思想,因为如果一个list存在环的话,那个两个pointer必定会相遇!~经过各种改进之后!~写出的原创 2014-12-04 13:40:55 · 332 阅读 · 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转载 2015-08-03 20:21:03 · 280 阅读 · 0 评论