链表
summerdj
这个作者很懒,什么都没留下…
展开
-
leetcode-21-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。 将两个有序链表按序合并。 主要是链表的操作,与链表有关的题就拿c++做了。思路:依次比较两个链表的当前元素的原创 2016-05-10 17:30:33 · 857 阅读 · 0 评论 -
C++ 单链表基本操作分析与实现
链表 链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成。每个结点包括两个部分:一个是存储数据元素的数据域,另一个是存储下一个结点地址的指针域。 相比于线性表顺序结构,链表比较方便插入和删除操作。创建头节点 手动new一个新的Node,将Node的next置为NULL即可转载 2016-05-05 16:17:20 · 910 阅读 · 0 评论 -
leetcode-25-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.You原创 2016-05-31 22:24:04 · 233 阅读 · 0 评论 -
leetcode-24-Swap Nodes in Pairs
题目:iven 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.交换链表每两个元素的位置。思路: 1.出现单个的情况链表不变 2.链表为空或者只有一个元素,返回head头原创 2016-05-19 21:50:56 · 570 阅读 · 2 评论 -
leetcode-19-Remove Nth Node From End of List
题意:删除链表从后往前开始的第n个节点。单链表的操作。别人说用python来实现单链表没有意义,好吧我不知道怎么反驳暂且附和好了。python用list可以实现堆栈和队列(pop(0)啥的…)。熟悉了链表的操作之后,本题的意思就在于从后往前的数,两个指针。第一个先走n步,然后第二个出发,到第一个继续走到最后一个元素的时候,第二个此时的位置的节点就是我们要删除的节点。要注意的是可能要删除的是第一个元素原创 2016-05-05 16:27:40 · 245 阅读 · 0 评论 -
leetcode-23-Merge k Sorted Lists
题意:合并k个有序链表。tags:divide and conquer。分治算法。思路在代码注释里面。 测试通过时间神奇的在32ms。一般为400ms。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)原创 2016-05-11 22:17:51 · 315 阅读 · 0 评论 -
leetcode-02-add two numbers-c++
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原创 2016-08-26 15:56:06 · 561 阅读 · 0 评论