Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
pancake-sorting.py 547 Bytes
Copy Edit Raw Blame History
kamyu authored 2019-01-06 17:19 +08:00 . Create pancake-sorting.py
# Time: O(n^2)
# Space: O(1)
class Solution(object):
def pancakeSort(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
def reverse(l, begin, end):
for i in xrange((end-begin) // 2):
l[begin+i], l[end-1-i] = l[end-1-i], l[begin+i]
result = []
for n in reversed(xrange(1, len(A)+1)):
i = A.index(n)
reverse(A, 0, i+1)
result.append(i+1)
reverse(A, 0, n)
result.append(n)
return result
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search