Skip to content

Latest commit

 

History

History

pancake-sorting

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Pancake sorting

Problem link

Solutions

Solution.cpp

// https://leetcode.com/problems/pancake-sorting

class Solution {
 public:
  vector<int> pancakeSort(vector<int>& A) {
    vector<int> ret;
    for (int i = A.size(); i; --i) {
      int cur = find(A.begin(), A.end(), i) - A.begin() + 1;
      ret.push_back(cur);
      reverse(A.begin(), A.begin() + cur);
      ret.push_back(i);
      reverse(A.begin(), A.begin() + i);
    }
    return ret;
  }
};

Tags