链表
HELLO_蓝猫
这个作者很懒,什么都没留下…
展开
-
链表反转
在知乎上看见浙大查重被查了这道题,写了一下。面试常见的一道题。原链表:head->1->2->3->null方法:遍历一次,头插法重新排列。head->nullhead->1->null....head->3->2->1->null#include <iostream>#include &...原创 2017-12-22 21:54:55 · 259 阅读 · 0 评论 -
Leetcode 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.Example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.此题题目描述不清 踩的很多/** * Definition for si原创 2017-12-27 20:12:03 · 130 阅读 · 0 评论 -
Leetcode 82. Remove Duplicates from Sorted List II
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode deleteDupli...原创 2018-03-13 11:33:20 · 127 阅读 · 0 评论 -
Leetcode 86. Partition List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode partition(L...原创 2018-03-20 14:31:07 · 144 阅读 · 0 评论 -
Leetcode 109. Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } *//** * Definition for a binary tree node. * pub...原创 2018-05-04 14:06:35 · 122 阅读 · 0 评论 -
Leetcode 147. Insertion Sort List
解法:找一个代排序列,一个排好序列,然后一个个比较,插入正确位置,重要一点,没插入完一个元素要更新rear的next。Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the fi...原创 2018-06-26 15:40:13 · 153 阅读 · 0 评论 -
Leetcode 160. 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 ↘ c...原创 2018-07-09 11:10:32 · 118 阅读 · 0 评论 -
LRU缓存 Leetocde146. LRU Cache
class Node{public: int key_t; int value_t; Node(int key,int value):key_t(key),value_t(value) { }};class LRUCache {public: list<Node> cache;//缓存 双向链表 方便插入...原创 2019-03-14 21:18:39 · 137 阅读 · 0 评论 -
链表中倒数第k个结点
#include <iostream>#include <memory>using namespace std;typedef struct LinkList{ int val; shared_ptr<LinkList> next;//智能指针和普通指针不要混合使用 https://blog.csdn.net/flowing_wind/articl...原创 2019-07-25 16:35:41 · 135 阅读 · 0 评论