【题目描述】

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 题解相关推荐

  1. Lintcode18 Subsets II solution 题解

    [题目描述] Given a list of numbers that may has duplicate numbers, return all possible subsets Notice:Ea ...

  2. Lintcode42 Maximum Subarray II solution 题解

    [题目描述] Given an array of integers, find two non-overlapping subarrays which have the largest sum.The ...

  3. Lintcode108 Palindrome Partitioning || solution 题解

    [题目描述] Given a strings, cutsinto some substrings such that every substring is a palindrome. Return t ...

  4. Lintcode363 Trapping Rain Water solution 题解

    [题目描述] Given n non-negative integers representing an elevation map where the width of each bar is 1, ...

  5. Lintcode132 Word Search || solution 题解

    [题目描述] Given a matrix of lower alphabetsand a dictionary.Find all words in the dictionary that can b ...

  6. Lintcode107 Word Break solution 题解

    [题目描述] Given a string s and a dictionary of words dict, determine if s can be break into a space-sep ...

  7. Lintcode189 First Missing Positive solution 题解

    [题目描述] Given an unsorted integer array, find the first missing positive integer. 给出一个无序的整数数组,找出其中没有出 ...

  8. Lintcode9 Fizz Buzz solution 题解

    [题目描述] Given number n. Print number from 1 to n. But: when number is divided by 3, print "fizz& ...

  9. Lintcode165 Merge Two Sorted Lists solution 题解

    [题目描述] Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted ...

最新文章

  1. 关于鼠标、键盘的几个例子
  2. (转载)Using GCC’s C++ Compiler
  3. 音乐文件基本格式,wave,mod,midi,mp3,wma,flac
  4. 安装rabbitmq和php扩展
  5. SylixOS下基于NUC970的NAND驱动
  6. B. Alyona and a tree(dsu on tree + bit)
  7. 【数据挖掘】挖掘建模-回归分析(1)
  8. 红旗Linux网卡绑定,Linux bonding 之balance-alb 原理介绍及其实现
  9. cad安装日志文件发生错误_苹果电脑Mac os系统重装时出现“准备安装时发生错误”解决方案...
  10. 微信小程序抖音实战-小视频弹幕
  11. 【研发设计】多人开发模式下的Git工作流介绍
  12. 如何使用串口来给STM32下载程序
  13. 【椭球大地测量学】Python及MATLAB实现大地坐标与空间直角坐标间的转换编程(含流程图)
  14. Android进程分类与管理
  15. 双十一优惠算不清凑单太麻烦?苏宁“千人千面”帮你搞定
  16. 为什么 MySQL 使用 B+ 树
  17. 防止按钮在短时间内被多次点击多次触发事件
  18. The reCAPTCHA was invalid. Go back and try it again.
  19. 【RF基础】RF调用python函数基础
  20. 这些你必须知道的 Linux 技能

热门文章

  1. myeclispe快捷键一\(≧▽≦)/终于也收藏了
  2. android 从文件制定位置读取数据
  3. android 系统状态栏的隐藏和显示
  4. android 密码加密
  5. DLL和COM的发展过程
  6. Dilated/Atrous conv 空洞卷积/多孔卷积
  7. 大型分布式系统需要考虑的问题
  8. 2.外部链接数据库报错Can't connect to mysql server on xxx.xxx.xxx.xxx(10038)
  9. 八月22日,django知识点总结:
  10. 基于visual Studio2013解决面试题之0802数字最多元素