

leetCode解题报告之Reorder List
source link: https://blog.csdn.net/ljphhj/article/details/21454705
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

题目:
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}
, reorder it to {1,4,2,3}
.
分析:
看到这个题目,我们首先容易想到的就是把链表分成两半,然后把后半部分链表进行逆序一下,之后再和前半部分结合起来就
可以将这道题目AC了!
两个要解决的问题:
1.如何快速的确定链表的中间位置的结点
2.如何将一个链表逆序,并且符合要求“You must do this in-place without altering the nodes' values”
代码实现:
Recommend
-
9
leetCode解题报告之构造二叉树(递归)_快乐de胖虎-CSDN博客此博文主要讲述了构造二叉树的两种方法: 1、通过先序和中序构造出二叉树( 来自leetCode OJ上的 题目:
-
10
比较简单的几道题,不做详细的解释,只为之后可以回头看看自己之前的代码!! 虽然几道题都比较简单,但感觉自己写得不好,希望博文如果被哪位大神看到,可以留言下写下你的做法! 题目一: Reverse Linked List II Reverse a link...
-
8
leetCode解题报告之O(n)线性时间求最大子序列和(Maximum Subarray)
-
14
leetCode解题报告之SingleNumberI,II(知识点:位运算)_快乐de胖虎-CSDN博客由于两题是姐妹题,所以放在同一个博文里了! 题目1: Given an array of integers, every element appears twice except for one. Find that single...
-
9
leetCode解题报告之Copy List with Random Pointer_快乐de胖虎-CSDN博客题目: 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. R...
-
9
题目一:Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false
-
10
题目一:Combinations Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3],...
-
7
题目一:Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not cont...
-
13
leetCode解题报告之Sort List_快乐de胖虎-CSDN博客勉励自己:坚持,谁说做工程的人不能学好算法!为面试做准备,加油!!!!! 题目: Sort a linked list in O(n log n) time using constant space...
-
8
leetCode解题报告之Insertion Sort List_快乐de胖虎-CSDN博客题目: Sort a linked list using insertion sort. 分析: 这个题目是想要让我们来做一个链表的插入排序问题. 这样,我们只要从...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK