每次找到当前最大数,转两下把最大数转到最右边.重复这个操作,直到都转完.

时间复杂度O(n**2)

class Solution(object):
def pancakeSort(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
maxA,index,ret,size = 0,-1,[],len(A)
if size==1: return [] for i, val in enumerate(A):
if val > maxA:
index,maxA = i,val A = A[index::-1] + ([] if index == size - 1 else A[index + 1:])
A.reverse()
ret = ret + [index + 1, size]+self.pancakeSort(A[:size - 1]) return ret

Leetcode 969. Pancake Sorting的更多相关文章

  1. 【LeetCode】969. Pancake Sorting 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟法 日期 题目地址:https://leetco ...

  2. 【leetcode】969. Pancake Sorting

    题目如下: Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.len ...

  3. 【LeetCode】Pancake Sorting(煎饼排序)

    这道题是LeetCode里的第969道题. 题目要求: 给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k <= A.length,然后反转 A 的前 k 个元素的顺序.我们要执行零 ...

  4. [Solution] 969. Pancake Sorting

    Difficulty: Medium Problem Given an array A, we can perform a pancake flip: We choose some positive ...

  5. LC 969. Pancake Sorting

    Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...

  6. 118th LeetCode Weekly Contest Pancake Sorting

    Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...

  7. [Swift]LeetCode969.煎饼排序 | Pancake Sorting

    Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...

  8. Pancake Sorting LT969

    Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...

  9. Leetcode 969. 煎饼排序

    969. 煎饼排序  显示英文描述 我的提交返回竞赛   用户通过次数134 用户尝试次数158 通过次数135 提交次数256 题目难度Medium 给定数组 A,我们可以对其进行煎饼翻转:我们选择 ...

随机推荐

  1. $Android制作和使用Nine-Patch图片

    Nine-Patch图片是一种经过特殊处理的png图片,能够指定图片的哪些区域可以被拉伸而哪些区域不可以. (一)普通图片被拉伸时的缺陷 有如下xml文件,其中子LinearLayout的背景图片设置 ...

  2. springboot获取URL请求参数的几种方法

    原文地址:http://www.cnblogs.com/xiaoxi/p/5695783.html 1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于pos ...

  3. 解决:Requested 'libdrm_radeon >= 2.4.56' but version of libdrm_radeon is 2.4.52

    checking for NOUVEAU... yes checking for RADEON... no configure: error: Package requirements (libdrm ...

  4. Xamarin简介与Xamarin支持MVC设计模式

    Create Native iOS, Android,Mac and Windows apps in C#. 官方网站:http://xamarin.com/ 使用武器 Run a C# app, g ...

  5. JVM内存的堆、栈和方法区

    JVM的内存分为堆.栈.方法区和程序计数器4个区域 存储内容:基本类型,对象引用,对象本身,class,常量,static变量 堆: 拥有者:所有线程 内容:对象本身,不存放基本类型和对象引用 垃圾回 ...

  6. POJO、Bean和JavaBean

    本文总结自: https://blog.csdn.net/chenchunlin526/article/details/69939337 POJO (plain pld java object) 一个 ...

  7. MySQL几个重要的目录

    MySQL几个重要的目录 1 数据库目录 /var/lib/mysql/ 2 配置文件 /usr/share/mysql(mysql.server命令及配置文件) 3 相关命令 /usr/bin(my ...

  8. maven 一个简单项目 —— maven权威指南学习笔记(三)

    目标: 对构建生命周期 (build  lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...

  9. thinkphp 多表事务处理

    try{ $this->user = D('User'); $this->user->startTrans(); //开始事务 $res = $this->user->S ...

  10. 【P2014】选课(树状DP)

    蒟蒻的第二道树形DP,话说看了这个题的正常做法之后一脸蒙,森林转二叉树??什么诡异的操作,蒟蒻完全没明白那个原理是啥...可能是当初没好好学吧..不管了,索性直接DP. 不难看出,这个题的DP方程和刚 ...