Lintcode99 Reorder List solution 题解
【题目描述】
Given a singly linked list L: L0→ L1→ … → Ln-1→ Ln
reorder it to: L0→ Ln→ L1→ Ln-1→ L2→ Ln-2→ …
给定一个单链表L:L0→L1→…→Ln-1→Ln,
重新排列后为:L0→Ln→L1→Ln-1→L2→Ln-2→…
必须在不改变节点值的情况下进行原地操作。
【题目链接】
www.lintcode.com/en/problem/reorder-list/
【题目解析】
题目要按照L0→Ln→L1→Ln-1→L2→Ln-2→…来排列,看例子1->2->3->4会变成1->4->2->3,拆开来看,是{1,2}和{4,3}的组合,而{4,3}是{3,4}的逆序。这样问题的解法就出来了。
首先可以将链表分为两部分,然后,将第二部分链表逆序,最后将链表重新组合。
【参考答案】
www.jiuzhang.com/solutions/reorder-list/
转载于:https://blog.51cto.com/13107314/1979170
Lintcode99 Reorder List solution 题解相关推荐
- Lintcode18 Subsets II solution 题解
[题目描述] Given a list of numbers that may has duplicate numbers, return all possible subsets Notice:Ea ...
- Lintcode42 Maximum Subarray II solution 题解
[题目描述] Given an array of integers, find two non-overlapping subarrays which have the largest sum.The ...
- Lintcode108 Palindrome Partitioning || solution 题解
[题目描述] Given a strings, cutsinto some substrings such that every substring is a palindrome. Return t ...
- Lintcode363 Trapping Rain Water solution 题解
[题目描述] Given n non-negative integers representing an elevation map where the width of each bar is 1, ...
- Lintcode132 Word Search || solution 题解
[题目描述] Given a matrix of lower alphabetsand a dictionary.Find all words in the dictionary that can b ...
- Lintcode107 Word Break solution 题解
[题目描述] Given a string s and a dictionary of words dict, determine if s can be break into a space-sep ...
- Lintcode189 First Missing Positive solution 题解
[题目描述] Given an unsorted integer array, find the first missing positive integer. 给出一个无序的整数数组,找出其中没有出 ...
- Lintcode9 Fizz Buzz solution 题解
[题目描述] Given number n. Print number from 1 to n. But: when number is divided by 3, print "fizz& ...
- Lintcode165 Merge Two Sorted Lists solution 题解
[题目描述] Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted ...
最新文章
- 关于鼠标、键盘的几个例子
- (转载)Using GCC’s C++ Compiler
- 音乐文件基本格式,wave,mod,midi,mp3,wma,flac
- 安装rabbitmq和php扩展
- SylixOS下基于NUC970的NAND驱动
- B. Alyona and a tree(dsu on tree + bit)
- 【数据挖掘】挖掘建模-回归分析(1)
- 红旗Linux网卡绑定,Linux bonding 之balance-alb 原理介绍及其实现
- cad安装日志文件发生错误_苹果电脑Mac os系统重装时出现“准备安装时发生错误”解决方案...
- 微信小程序抖音实战-小视频弹幕
- 【研发设计】多人开发模式下的Git工作流介绍
- 如何使用串口来给STM32下载程序
- 【椭球大地测量学】Python及MATLAB实现大地坐标与空间直角坐标间的转换编程(含流程图)
- Android进程分类与管理
- 双十一优惠算不清凑单太麻烦?苏宁“千人千面”帮你搞定
- 为什么 MySQL 使用 B+ 树
- 防止按钮在短时间内被多次点击多次触发事件
- The reCAPTCHA was invalid. Go back and try it again.
- 【RF基础】RF调用python函数基础
- 这些你必须知道的 Linux 技能
热门文章
- myeclispe快捷键一\(≧▽≦)/终于也收藏了
- android 从文件制定位置读取数据
- android 系统状态栏的隐藏和显示
- android 密码加密
- DLL和COM的发展过程
- Dilated/Atrous conv 空洞卷积/多孔卷积
- 大型分布式系统需要考虑的问题
- 2.外部链接数据库报错Can't connect to mysql server on xxx.xxx.xxx.xxx(10038)
- 八月22日,django知识点总结:
- 基于visual Studio2013解决面试题之0802数字最多元素