leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0969.cpp (604B)


0 class Solution {
1 public:
2 vector<int> pancakeSort(vector<int> &arr) {
3 vector<int> res;
5 for (int i = arr.size() - 1, low, high; i >= 0; i--) {
6 if (arr[i] == i + 1) continue;
8 low = 0, high = 0;
9 while (arr[high] != i + 1)
10 high++;
12 res.push_back(high + 1);
13 while (low < high)
14 swap(arr[low++], arr[high--]);
16 low = 0, high = i;
17 res.push_back(high + 1);
18 while (low < high)
19 swap(arr[low++], arr[high--]);
20 }
21 return res;
22 }
23 };