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 066a216 commit 0997ae0Copy full SHA for 0997ae0
Leet_Code/Random Problem/969-PancakeSorting.cpp
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ vector<int> pancakeSort(vector<int>& arr) {
4
+ int n = arr.size();
5
+ std::vector<int> b(arr);
6
+ sort(b.rbegin(), b.rend());
7
+
8
+ std::vector<int> res;
9
+ for(int p = 0; p < n; p++){
10
+ int idx(-1);
11
+ for(int u = 0; idx < 0 && u < n; u++){if(arr[u] == b[p]){idx = u;}}
12
+ res.push_back(idx + 1); std::reverse(arr.begin(), arr.begin() + idx + 1);
13
+ res.push_back(n - p); std::reverse(arr.begin(), arr.begin() + n - p);
14
+ }
15
16
+ return res;
17
18
+};
0 commit comments