
链表
谛听-
线上幽灵
展开
-
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....原创 2018-03-03 13:03:44 · 210 阅读 · 0 评论 -
leetcode---insertion-sort-list---链表
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */原创 2018-01-21 21:31:53 · 203 阅读 · 0 评论 -
leetcode---median-of-two-sorted-arrays---链表
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).class Solution {public: double fi原创 2017-11-01 19:37:04 · 283 阅读 · 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 linke原创 2017-10-31 18:44:59 · 372 阅读 · 0 评论 -
leetcode---swap-nodes-in-pairs---链表
Given a linked list, swap every two adjacent nodes and return its head. For example, Given1->2->3->4, you should return the list as2->1->4->3. Your algorithm should use only constant space. You may原创 2017-10-30 20:11:49 · 256 阅读 · 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: Given1->2->3->4->5->NULL, m = 2 and n = 4, return1->4->3->2->5->NULL. Note: Given m, n satisfy the followi原创 2017-10-29 17:13:06 · 234 阅读 · 0 评论 -
链表---在有序链表中寻找中点的两种方式
当链表中的节点数为偶数,代码1找到的中点偏前,代码2找的中点偏后 如:1, 2, 3, 4 代码1找到的中点为2,代码2找到的中点为3代码1 ListNode *findMid(ListNode *head) { ListNode *fast = head; ListNode *slow = head; while(fast->nex原创 2017-10-29 16:08:46 · 795 阅读 · 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./** * Definition for singly-linked l原创 2017-10-29 13:57:49 · 340 阅读 · 0 评论 -
leetcode---merge-k-sorted-lists---链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next;原创 2017-10-25 19:13:02 · 302 阅读 · 0 评论 -
leetcode---rotate-list---链表
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given1->2->3->4->5->NULLand k =2, return4->5->1->2->3->NULL./** * Definition for singly-linked list. *原创 2017-10-25 18:47:26 · 211 阅读 · 0 评论 -
leetcode---remove-duplicates-from-sorted-list---链表
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given1->1->2, return1->2. Given1->1->2->3->3, return1->2->3./** * Definition for singly-linke原创 2017-10-24 19:11:49 · 254 阅读 · 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 th原创 2017-10-24 18:30:21 · 282 阅读 · 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./** * Definition for singly-linked list. * struct ListNode原创 2017-10-21 18:04:27 · 215 阅读 · 0 评论 -
leetcode---linked-list-cycle-ii---链表
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it without using extra space?/** * Definition for singly-linked list. * struc原创 2017-10-20 18:37:43 · 209 阅读 · 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?/** * Definition for singly-linked list. * struct ListNode { * int val; * Lis原创 2017-10-19 21:26:54 · 332 阅读 · 0 评论 -
leetcode---reorder-list---链表中点、逆转
Given a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You must do this in-place without altering the nodes’ values. For example, Given{1,2,3,4}, reorder i原创 2017-10-18 19:49:16 · 280 阅读 · 0 评论 -
leetcode---remove-nth-node-from-end-of-list---链表
Given a linked list, remove the n th 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 linked原创 2017-10-16 14:50:24 · 234 阅读 · 0 评论 -
leetcode---Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in plac原创 2017-04-05 20:35:35 · 609 阅读 · 0 评论 -
leetcode---Reverse Linked List---链表
Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solu原创 2016-11-16 13:53:18 · 430 阅读 · 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 --> 5 /** * Definition for sin原创 2016-11-14 17:30:59 · 280 阅读 · 0 评论 -
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 ↘原创 2016-10-22 20:46:33 · 296 阅读 · 0 评论 -
leetcode---Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(原创 2016-10-16 13:51:31 · 336 阅读 · 0 评论 -
leetcode---Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */cl原创 2016-10-14 21:16:09 · 371 阅读 · 0 评论