leetcode969
class Solution(object):
def pancakeSort(self, A: 'List[int]') -> 'List[int]':
n = len(A)
result = list()
while n > 1:
idx = A.index(n)
dif = n - 1 - idx
pre = []
if dif != 0:
if idx != 0:
result.append(idx+1)
result.append(n)
pre = A[idx+1:]
pre.reverse()
A = pre + A[:idx]
n = len(A)
#print(A)
return result
从大到小寻找每个数字的位置,将其先移动到第一个位置,再将其移动到其数字应该的位置(index==num-1)。
leetcode969的更多相关文章
- [Swift]LeetCode969.煎饼排序 | Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...
- LeetCode969. 煎饼排序
问题:969. 煎饼排序 给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k <= A.length,然后反转 A 的前 k 个元素的顺序.我们要执行零次或多次煎饼翻转(按顺序一次接 ...
随机推荐
- robot framework关键词记录单(更新中)
1.select Radio Button groupname value 选择单选按钮 A)适用于input的html单选框,属性中包含name以及value如:Select Radio Butt ...
- 算法题:给出一组数字,拼接一个最大的值 PHP
举例如下:'9235','42','9','5','8','32','136','343','45' 则拼接的最大的数为 : 9-9235-8-5-45-42-343-32-136 网上坑多,想了很久 ...
- win10 uwp 读取resw资源文件
ResourceContext resourceContext = ResourceContext.GetForViewIndependentUse(); ResourceMap resourceMa ...
- Verilog手绘FVH信号
Verilog手绘FVH信号 `timescale 1ns / 1ps //////////////////////////////////////////////////////////////// ...
- 使用xheditor时 cloneRange错误 ext.net
使用ext.net 加 xheditor时,一直报 cloneRange错误. 于是 按照说明但独使用xheditor ,检查无错,正常使用, 因此排除版本问题. <ext:panel ru ...
- RN 获取组件的宽度和高度
https://www.cnblogs.com/zhiyingzhou/p/7471212.html https://blog.csdn.net/calvin_zhou/article/details ...
- 虚拟机中的linux系统文件突然全部变成只读的问题
当宿主系统和虚拟机的IO都比较繁忙时,虚拟机的IO请求得不到及时的响应.虚拟机Linux不知道自己运行在虚拟机里面,会认为是磁盘IO错误,为了保护磁盘数据会remount分区为只读. 这时候如果只是对 ...
- flask教程
http://docs.jinkan.org/docs/flask/ https://dormousehole.readthedocs.io/en/latest/ https://m.w3cschoo ...
- 打印上三角或下三角矩阵(9x9) - perl, R
欲打印矩阵位置示意图 #!/usr/bin/perl -w use strict; ## bottom left ..) { ..) { if($col <= $row) { print $ro ...
- springboot集成schedule
背景 在项目开发过程中,我们经常需要执行具有周期性的任务.通过定时任务可以很好的帮助我们实现. 我们拿常用的几种定时任务框架做一个比较: 从以上表格可以看出,Spring Schedule框架功能完善 ...