Skip to content

Commit d218581

Browse files
committed
Time: 0 ms (100%), Space: 17.6 MB (90.64%) - LeetHub
1 parent 4651e0c commit d218581

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(n^2)
2+
# space complexity: O(n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def pancakeSort(self, arr: List[int]):
8+
result = []
9+
for lastIdx in range(len(arr), 1, -1):
10+
currIdx = arr.index(lastIdx)
11+
result.extend([currIdx + 1, lastIdx])
12+
arr = arr[:currIdx:-1] + arr[:currIdx]
13+
return result
14+
15+
16+
arr = [3, 2, 4, 1]
17+
print(Solution().pancakeSort(arr))
18+
arr = [1, 2, 3]
19+
print(Solution().pancakeSort(arr))

0 commit comments

Comments
 (0)