码迷,mamicode.com
首页 >  
搜索关键字:linked_list    ( 3784个结果
114. Flatten Binary Tree to Linked List
一、题目 1、审题 2、分析 给出一棵二叉树,按照先序遍历顺序组成一棵斜右二叉树。 二、解答 1、思路: 方法一、 采用一个栈进行先序遍历,遍历时将节点重新组装。 方法二、 采用递归 递归实现 右-->左-->根 遍历,并拼接原二叉树的节点顺序。 方法三、 采用 Morris Traversal 方 ...
分类:其他好文   时间:2018-10-04 23:06:15    阅读次数:230
leetcode86 - Partition List - medium
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 o ...
分类:其他好文   时间:2018-10-04 10:55:20    阅读次数:151
19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head. Example: Note: Given n will always be valid. Follow up: Could you ...
分类:其他好文   时间:2018-10-04 08:50:55    阅读次数:135
[LeetCode] 382. Linked List Random Node 链表随机节点
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Follow up:Wha ...
分类:其他好文   时间:2018-10-03 21:03:29    阅读次数:147
leetcode#24 Swap Nodes in Pairs
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。 示例: 给定 1 2 3 4, 你应该返回 2 1 4 3. 说明: 你的算法只能使用常数的额外空间。 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 ...
分类:其他好文   时间:2018-09-29 14:32:33    阅读次数:168
02-线性结构3 Reversing Linked List (25 分)
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, ...
分类:其他好文   时间:2018-09-29 14:21:13    阅读次数:105
LeetCode算法题python解法:24. Swap Nodes in Pairs
原题: Given a linked list, swap every two adjacent nodes and return its head. Example: Given 1->2->3->4, you should return the list as 2->1->4->3. Note: ...
分类:编程语言   时间:2018-09-26 17:18:36    阅读次数:169
92. Reverse Linked List II
一、题目 1、审题 2、分析 给出一个整数链表,翻转从第 m 到 n 的所有节点(m <= n)。 二、解答 1、思路: 方法一、用到了 6 个指针变量 ①、新建一个伪头结点,指向 head,且一指针向前移动直到 index == m; ②、若 m <= index <= n ,则将之间的节点插入一 ...
分类:其他好文   时间:2018-09-26 12:19:05    阅读次数:116
leetcode203. Remove Linked List Elements
很经典的一道题,但波波老师讲出了新的东西。设立虚拟结点,因为每次循环cur->next只有头结点无法考虑,但是你要是单独考虑头结点,万一头结点删除你还需要再考虑下一头结点,就形成了很麻烦的while结构。有了虚拟头结点,问题全都解决了。 ...
分类:其他好文   时间:2018-09-24 00:26:46    阅读次数:235
114. Flatten Binary Tree to Linked List
把左边=null, 把最左边遍历到null 保证已经flatten 然后再弄右边 然后把root.right跟左边连接,再把右边连接到root.right的最下面 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/dis ...
分类:其他好文   时间:2018-09-22 01:05:14    阅读次数:144
3784条   上一页 1 ... 57 58 59 60 61 ... 379 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!