LintCode学习之链表
文章平均质量分 66
zy300212
这个作者很懒,什么都没留下…
展开
-
在O(1)时间复杂度删除链表节点
/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }原创 2016-01-16 17:21:06 · 279 阅读 · 0 评论 -
删除链表中的元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: /** * @原创 2016-01-13 19:16:54 · 199 阅读 · 0 评论 -
删除排序链表中的重复数字 II
/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }原创 2016-01-14 00:11:13 · 427 阅读 · 0 评论 -
两个链表的交叉——值得注意的错误
class Solution {public: /** * @param headA: the first list * @param headB: the second list * @return: a ListNode */ ListNode *getIntersectionNode(ListNode *headA, ListNode原创 2016-01-21 14:43:06 · 202 阅读 · 0 评论 -
带环链表
class Solution {public: /** * @param head: The first node of linked list. * @return: True if it has a cycle, or false */ bool hasCycle(ListNode *head) { // write your c原创 2016-01-21 01:43:42 · 276 阅读 · 0 评论 -
重排链表
给定一个单链表L: L0→L1→…→Ln-1→Ln,重新排列后为:L0→Ln→L1→Ln-1→L2→Ln-2→…必须在不改变节点值的情况下进行原地操作。class Solution {public: /** * @param head: The first node of linked list. * @return: void */原创 2016-01-20 23:21:27 · 398 阅读 · 0 评论 -
合并k个排序链表
class Solution {public: /** * @param lists: a list of ListNode * @return: The head of one sorted list. */ ListNode *mergeKLists(vector &lists) { // write your code here原创 2016-01-20 17:47:46 · 240 阅读 · 0 评论 -
翻转链表1和2
class Solution {public: /** * @param head: The first node of linked list. * @return: The new head of reversed linked list. */ ListNode *reverse(ListNode *head) { // wri原创 2016-01-19 23:45:53 · 186 阅读 · 0 评论 -
链表排序
class Solution {public: ListNode *sortList(ListNode *head) { if(head == NULL || head->next ==NULL){return head;} ListNode *mid = getMid(head); ListNode *right = mid->nex原创 2016-01-19 21:18:12 · 216 阅读 · 0 评论 -
链表插入排序
class Solution {public: /** ---->[1]----> [3]----> [2]----->[0]---->[NULL](原链表) head 1->next 3->next 2->next 0->next ----->[1]---->[NULL](从原链表中取第1个节点作为只有一个节点的有序链表) dum原创 2016-01-17 14:13:44 · 233 阅读 · 0 评论 -
删除链表中倒数第n个节点
/** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * }原创 2016-01-16 18:24:27 · 214 阅读 · 0 评论 -
链表求和
给出两个链表 3->1->5->null 和 5->9->2->null,返回8->0->8->null/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL)原创 2016-01-14 02:12:18 · 215 阅读 · 0 评论