List
文章平均质量分 59
所难
这个作者很懒,什么都没留下…
展开
-
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-08-17 22:11:28 · 401 阅读 · 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. Solution: Code: /** * D原创 2014-07-29 16:25:10 · 391 阅读 · 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. Solution: Code:原创 2014-08-13 15:03:25 · 302 阅读 · 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? Solution: Code: /** * Definition for singly-linked list. * struct ListNode原创 2014-07-29 09:55:17 · 426 阅读 · 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 to原创 2014-07-29 09:33:01 · 368 阅读 · 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? Solution: Code: /** * Definition fo原创 2014-07-29 09:50:03 · 376 阅读 · 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-08-08 18:15:48 · 342 阅读 · 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. Solution: Code:原创 2014-08-08 18:20:37 · 199 阅读 · 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-08-08 14:04:51 · 230 阅读 · 0 评论 -
LeetCode-Insertion Sort List
Sort a linked list using insertion sort. Solution: Code:原创 2014-07-28 16:11:29 · 304 阅读 · 0 评论 -
LeetCode-Sort List
Sort a linked list in O(n log n) time using constant space complexity. Solution: Merge Sort原创 2014-07-28 14:56:19 · 438 阅读 · 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 t原创 2014-08-07 14:46:29 · 273 阅读 · 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-08-19 13:44:16 · 426 阅读 · 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-08-18 11:41:31 · 326 阅读 · 0 评论 -
LeetCode-Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Solution: Code:原创 2014-08-17 22:59:19 · 288 阅读 · 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-08-17 22:27:14 · 256 阅读 · 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. Solution: Code:原创 2014-08-03 21:28:37 · 385 阅读 · 0 评论