#include <leetcode.h>
◆ pancakeSort()
vector< int > leetcode::pancake_sorting::Solution::pancakeSort |
( |
vector< int > & |
arr | ) |
|
|
static |
在文件 leetcode.cpp 第 3064 行定义.
3065 auto ans = vector<int>();
3066 const int n = arr.size();
3067 auto *current =
new int[n];
3068 auto *sorted =
new int[n];
3069 for(
int i = 0; i < n; i++) {
3070 current[i] = arr[i];
3073 sort(sorted, sorted + n);
3075 for(
int i = n - 1; i >= 0; i--) {
3076 if(current[i] != sorted[i]) {
3077 const int target = sorted[i];
3079 for(
int j = 0; j <= i; j++) {
3080 if(current[j] == target) {
3088 ans.push_back(target_i);
3089 for(
int j = 0; j < target_i / 2; j++) {
3090 swap(current[j], current[target_i - j - 1]);
该类的文档由以下文件生成: