![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
链表
文章平均质量分 65
_xiaoyuer
世界一定有光
展开
-
二叉树与双向链表
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。指针的指针,神奇的好用/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(原创 2017-03-24 20:13:55 · 1071 阅读 · 0 评论 -
LeetCode - 328 - 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原创 2017-08-10 15:43:28 · 162 阅读 · 0 评论 -
LeetCode - 61 - Rotate List
Given 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.一个链表的,重新衔接。最开始一直TLE,我还十分纳闷,原创 2017-07-20 09:35:54 · 160 阅读 · 0 评论 -
LeetCode - 234 - Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?判断一个链表是不是回文,我的方法是把前一半链表翻转,然后再同时扫描,判断值是否相等。时间复杂度O(n),至于空间复杂度,我觉得翻转一个链表的空间复杂度是原创 2017-07-23 10:30:40 · 146 阅读 · 0 评论 -
LeetCode - 206/92 - Reverse Linked List
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原创 2017-07-20 16:14:50 · 172 阅读 · 0 评论 -
LeetCode - 199 - Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2017-07-22 13:25:24 · 169 阅读 · 0 评论 -
LeetCode - 445 - Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return i原创 2017-07-21 15:19:35 · 168 阅读 · 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 ↘原创 2017-07-20 16:22:05 · 157 阅读 · 0 评论 -
LeetCode - 86 - 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 t原创 2017-07-20 15:39:17 · 174 阅读 · 0 评论 -
LeetCode - 83/82/203/19 - Remove Elements from Linked List
83 - Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3原创 2017-07-14 09:25:59 · 244 阅读 · 0 评论 -
LeetCode - 141/142 - Linked List Cycle
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断链表是否成环。设定两个指针,一个每次走一步,一个每次走两步,如果都不为空且相等了,就说明成环原创 2017-07-15 14:25:09 · 163 阅读 · 0 评论 -
LeetCode - 21/23/88 - Merge Sorted Lists/Array
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.唔,这题的思路,咋写啊。。。就是,比较两个链表当前值的大小,取值小的那个。时间复杂度O(n),空间复杂度O原创 2017-07-14 09:27:12 · 181 阅读 · 0 评论 -
LeetCode - 2 - Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i原创 2017-06-21 20:10:16 · 169 阅读 · 0 评论 -
LeetCode - 24 - Swap Nodes in Pairs(交换链表结点)
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl原创 2017-09-07 16:42:51 · 254 阅读 · 0 评论