Leetcode 969. Pancake Sorting
每次找到当前最大数,转两下把最大数转到最右边.重复这个操作,直到都转完.
时间复杂度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的更多相关文章
- 【LeetCode】969. Pancake Sorting 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟法 日期 题目地址:https://leetco ...
- 【leetcode】969. Pancake Sorting
题目如下: Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.len ...
- 【LeetCode】Pancake Sorting(煎饼排序)
这道题是LeetCode里的第969道题. 题目要求: 给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k <= A.length,然后反转 A 的前 k 个元素的顺序.我们要执行零 ...
- [Solution] 969. Pancake Sorting
Difficulty: Medium Problem Given an array A, we can perform a pancake flip: We choose some positive ...
- LC 969. Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...
- 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 ...
- [Swift]LeetCode969.煎饼排序 | Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...
- Pancake Sorting LT969
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...
- Leetcode 969. 煎饼排序
969. 煎饼排序 显示英文描述 我的提交返回竞赛 用户通过次数134 用户尝试次数158 通过次数135 提交次数256 题目难度Medium 给定数组 A,我们可以对其进行煎饼翻转:我们选择 ...
随机推荐
- 关于SIM800C MINI V4.0 V4版本 5v供电模块重启问题
现象描述 模块不停重启,发送AT时候能看到,不停的回复Call Ready 或者SIM卡确认没问题,但是NET指示灯一直不能进入3秒闪烁的状态. 1.内核要求 SIM800C内核要求需要电源有瞬间有2 ...
- List Slice in Python(Compared with Java)
Python: 在Python中, 对于list, 切片会返回一个新的list, 而不会改变原有的list. 注意这儿说的"不会改变原有的list"指的是下面的这种情况: a = ...
- 一个用 C# 实现操作 XML 文件的公共类代码
using System; using System.IO; using System.Data; using System.Xml; using System.Xml.XPath; namespac ...
- Python之面向对象进阶------反射(Day26)
一 classmethod class Classmethod_Demo(): role = 'dog' @classmethod def func(cls): print(cls.role) Cla ...
- Ubuntu 16.04 php卸载
1.卸载 apache2 sudo apt-get --purge remove apache2* sudo apt-get autoremove apache2 (--purge 是完全删除并且不保 ...
- 【TopCoder】SRM152 DIV2总结
为什么平常刷的时候感觉还不错,比赛的时候只能做出来一道题=.= 250分题:大水题,根据题目规则把一个字符串翻译成数字,直接代码:GitHub 我是通过遍历一个个数出来的,看到大神的解法是把字符用‘- ...
- 【CodeChef】Enormous Input Test
The purpose of this problem is to verify whether the method you are using to read input data is suff ...
- jQuery 中让我误解的那些方法
至今我都不能说把 jQuery 中的方法在实践中都用了一遍, 一部分是用不到,一部分则是我未能体会它的魅力, 所以今天就来收录一下,那些从我们之间溜走的美丽. $.fn.add() 一开始对它的理解就 ...
- 解决noSession问题
1.问题描述:对于根据id查询时,在dao通过load方式查询对象时,加载页面会报 noSession异常. 严重: Servlet.service() for servlet [springDisp ...
- input ajax自动补全
页面 <div class="manage-Car-add-info-sn"> <p style="width:25%; height:70%;floa ...