
链表
永远的EMT
每天时刻保持超越自我的意识
展开
-
【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? 题解:判断一个单链表是不是回文串,可以将后半部分进行反转。注意这里找中间位置可以用两指针的方法,设置快慢指针,快指针是慢指针两倍速度从而快指针到结尾时可以保证慢原创 2017-09-11 16:25:23 · 330 阅读 · 0 评论 -
【LeetCode】138. Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 题解:复制一个随机链表,本题复制时先用map标记原地址到复制地址的映...原创 2018-10-15 22:48:47 · 160 阅读 · 0 评论 -
【LeetCode】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 题解:给定一个链表有序的转成平衡BST,关键这里我用额外空间MLE所以应该在链表上直接进行,最优化的应该是设计两个指针,一个slow一个fast用来遍历中间节点,然后左右子...原创 2018-10-19 22:22:06 · 177 阅读 · 0 评论 -
【LeetCode】Reverse Linked List II
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->3->2->5-...原创 2018-10-22 21:39:00 · 158 阅读 · 0 评论 -
【LeetCode】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...原创 2018-11-07 01:45:20 · 159 阅读 · 0 评论