原题题目
代码实现(首刷自解)
class Solution {
public:vector<int> prevPermOpt1(vector<int>& arr) {
int retpos = -1,changepos = -1;for(int pos = arr.size()-2;pos>=0;--pos){
if(arr[pos] <= arr[pos+1]) continue;retpos = pos;break;}if(retpos == -1) return arr;for(int i=retpos+1,temp = -1;i<arr.size();++i){
if(arr[i] < arr[retpos] && (temp == -1 || arr[i] > temp) ){
changepos = i;temp = max(temp,arr[i]);}}swap(arr[retpos],arr[changepos]);return arr;}
};