We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4651e0c commit d218581Copy full SHA for d218581
1009-pancake-sorting/1009-pancake-sorting.py
@@ -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
0 commit comments