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

时间复杂度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. bacula 备份恢复

    一.数据恢复: 在bacula服务器执行: /opt/bacula/etc/ bconsole #进入交互窗口 *restore #输入restore恢复命令 Automatically select ...

  2. selenium模块控制浏览器

    利用selenium模块控制浏览器 导入selenium模块:from selenium import webdriver browserFirefox = webdriver.Firefox()#打 ...

  3. mybatis中collection和association的作用以及用法

    deptDaoMapper.xml 部门对应员工(1对多的关系) <resultMap type="com.hw.entity.Dept" id="deptinfo ...

  4. 常用的机器学习&数据挖掘知识点

    Basis(基础):MSE(Mean Square Error 均方误差),LMS(LeastMean Square 最小均方),LSM(Least Square Methods 最小二乘法),MLE ...

  5. 【leetcode刷题笔记】Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  6. 主攻ASP.NET.4.5.1 MVC5.0之重生:政府行政网站常用友情链接跳转javascript[干货分享]

    <!-----------------------------------> <script language="JavaScript" type="t ...

  7. Cocos2d-x项目移植到WP8系列之二:开篇

    原文链接: http://www.cnblogs.com/zouzf/p/3970130.html 开发环境一笔带过吧,主板和CPU要支持虚拟化技术,要开启才行,装个64位win8.1系统,win8不 ...

  8. Android修改init.rc和init.xx.rc文件【转】

    本文转载自:https://blog.csdn.net/u013686019/article/details/47981249 一.文件简介 init.rc:Android在启动过程中读取的启动脚本文 ...

  9. c# 判断字符串中是否含有汉字,数字

    正则表达式使用时需要引用 using System.Text.RegularExpressions; private void buttonX1_Click(object sender, EventA ...

  10. adb 解说

    ADB是一个 客户端-服务器端 程序, 其中客户端是你用来操作的电脑, 服务器端是android设备. 先说安装方法, 电脑上需要安装客户端. 客户端包含在sdk里. 设备上不需要安装, 只需要在手机 ...