969. Pancake Sorting
https://leetcode.com/problems/pancake-sorting/description/
/*
* @lc app=leetcode id=969 lang=cpp
*
* [969] Pancake Sorting
*/
// @lc code=start
class Solution {
public:
vector<int> pancakeSort(vector<int>& A) {
vector<int> res;
for (int x = A.size(); x > 0; --x) {
int k = 0;
for (; A[k] != x; ++k) continue;
reverse(A.begin(), A.begin() + k + 1);
res.push_back(k + 1);
reverse(A.begin(), A.begin() + x);
res.push_back(x);
}
return res;
}
};
// @lc code=end
Last updated