LintCode问题图解-5

作者: billliu_0d62 | 来源:发表于2017-09-24 15:24 被阅读8次

    本文准备讲解1个简单的算法编程问题, 这个算法编程问题来自LintCode平台。不了解.LintCode平台的读者可以阅读笔者文章(在线编程平台推荐-LeetCode)。问题的英文版本描述如下:

    Recover Rotated Sorted Array

    Given a rotated sorted array, recover it to sorted array in-place.

    Clarification

    What is rotated array?

    For example, the orginal array is [1,2,3,4], The rotated array of it can be [1,2,3,4], [2,3,4,1], [3,4,1,2], [4,1,2,3]

    Example

    [4, 5, 1, 2, 3]->[1, 2, 3, 4, 5]

    问题的中文版本描述:

    修复转动排序数组

    给定一个转动排序数组,将其修复为排序完成数组。

    说明

    什么是转动数组?

    比如,原始数组为[1,2,3,4], 则其转动数组可以是[1,2,3,4], [2,3,4,1], [3,4,1,2], [4,1,2,3]

    样例

    [4, 5, 1, 2, 3]->[1, 2, 3, 4, 5]

    标准的算法包含多次的元素顺序处理,参见下图方案:

    标准的方案

    现在公布1种高效的算法方案,该方案对应 LintCode 平台表现更强。

    Collections.sort(nums);

    相关文章

      网友评论

        本文标题:LintCode问题图解-5

        本文链接:https://www.haomeiwen.com/subject/wxbkextx.html