![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
链表
liuchenjane
这个作者很懒,什么都没留下…
展开
-
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 following co原创 2016-10-08 19:40:38 · 214 阅读 · 0 评论 -
双向链表的基本操作
双向链表的建立,打印,查找,增删#include <iostream>#include <vector>#include <algorithm>#include <string>#include <climits>using namespace std;//以下是关于双链表的操作struct dnode { int data; dnode* left; dnod原创 2017-05-11 17:24:10 · 322 阅读 · 0 评论 -
单链表总结
#include <iostream>#include <vector>#include <string>using namespace std;void print(int a[], int n){ for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;}//直接插入排序void原创 2017-04-28 16:36:30 · 635 阅读 · 0 评论 -
循环链表的判断
重新理解了快慢指针,判断是否有循环这一问题。 142. Linked List Cycle II 287. Find the Duplicate Number 先看第一个:判断循环链表 Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do转载 2017-03-04 21:28:30 · 1687 阅读 · 0 评论 -
460. LFU Cache
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key转载 2017-02-08 08:57:35 · 571 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解法一:依次合并两个,直至把所有的合并完。 ListNode* mergeKLists(vector& lists) { int n=lists.size();转载 2017-01-14 16:03:40 · 366 阅读 · 0 评论 -
148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.思路:采用类似数组的分治排序的思想对链表进行排序,使其时间复杂度达到 O(n log n) 的要求。先将链表分割成两部分,分别对其排好序。再将排好序的链表进行合并。/** * Definition for singly-linked list.原创 2016-12-17 20:56:12 · 269 阅读 · 0 评论 -
143. Reorder List
143. Reorder ListGiven 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转载 2016-12-17 20:22:59 · 273 阅读 · 0 评论 -
445. Add Two Numbers II
445. Add Two Numbers IIYou are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two nu原创 2016-10-31 19:49:48 · 958 阅读 · 0 评论 -
147. Insertion Sort List
147. Insertion Sort ListSort a linked list using insertion sort.题意:插入排序的链表实现。思路:定义两个链表指针start和end,start指向已经排好序的链表的指针头,end指向已经排好序的指针的结尾。例如对于:eg: 1->2->4->5以排好序)->3->......;这里start指向1,end指向5原创 2016-11-05 20:48:45 · 356 阅读 · 0 评论 -
Reverse Linked List
Reverse Linked ListReverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?解法1:迭代转载 2016-09-26 10:19:31 · 283 阅读 · 0 评论 -
Rotate List
61. Rotate ListGiven 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.回想rotate Arr原创 2016-09-26 15:19:23 · 250 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->原创 2016-09-28 09:50:20 · 236 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.转载于https://discuss.leetcode.com/topic/8141/sha转载 2016-10-04 20:36:44 · 325 阅读 · 0 评论 -
约瑟夫问题解答
问题: 编号为1,2,····n的n个人按顺时针做成一圈,一开始任选一个正整数作为报数的上限值m,从第一个人开始按顺时针方向自1开始顺时针报数,报到m时停止,这个人出列。从他在顺时针方向上的下一个人开始重新报数,如此下去,直至所有人出列。下面是用STL中的list#include <iostream>#include <list>#include <algorithm>using names原创 2017-05-30 21:38:00 · 660 阅读 · 0 评论