麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

LeetCode 31. Next Permutation

2019-11-14 08:44:46
字體:
來源:轉載
供稿:網友

描述 Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).

The replacement must be in-place, do not allocate extra memory.

Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column. 1,2,3 → 1,3,2 3,2,1 → 1,2,3 1,1,5 → 1,5,1

分析 下一個排列算法流程

代碼

class Solution {public: void nextPermutation(vector<int> &num) { next_permutation(num.begin(), num.end()); } template<typename BidiIt> bool next_permutation(BidiIt first, BidiIt last) { // Get a reversed range to simplify reversed traversal. const auto rfirst = reverse_iterator<BidiIt>(last); const auto rlast = reverse_iterator<BidiIt>(first); // Begin from the second last element to the first element. auto pivot = next(rfirst); // Find `pivot`, which is the first element that is no less than its // successor. `PRev` is used since `pivort` is a `reversed_iterator`. while (pivot != rlast && *pivot >= *prev(pivot)) ++pivot; // No such elemenet found, current sequence is already the largest // permutation, then rearrange to the first permutation and return false. if (pivot == rlast) { reverse(rfirst, rlast); return false; } // Scan from right to left, find the first element that is greater than // `pivot`. auto change = find_if(rfirst, pivot, bind1st(less<int>(), *pivot)); swap(*change, *pivot); reverse(rfirst, pivot); return true; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产午夜免费视频 | 有色视频在线观看 | 天天看逼 | 国色天香综合网 | 精品国产一区二区三区四区在线 | 2021国产精品视频 | 牛牛热这里只有精品 | 欧美另类69xxxxx 视频 | 日韩毛片免费观看 | 九九色在线观看 | 欧美一区二区三区久久精品视 | 日韩激情一区 | 黄色网址在线免费播放 | 国产一区二区免费看 | 四季久久免费一区二区三区四区 | 国产精品久久久免费观看 | 免费看国产 | 成人一级免费视频 | 久久久久久久久久久亚洲 | 久久久久久久久日本理论电影 | 久久影院在线观看 | 成人精品 | 看a级毛片 | 国产1区在线观看 | 久久精品日产第一区二区三区 | 男女一边摸一边做羞羞视频免费 | 成人免费视频视频在线观看 免费 | 一区二区三区精品国产 | av在线免费网址 | 亚洲一区久久 | 欧美毛片 | av成人免费 | 看免费一级毛片 | 成人免费福利网站 | 天天看成人免费毛片视频 | 欧美亚洲免费 | 亚洲精品成人久久 | 91精品国产综合久久婷婷香蕉 | 92看片淫黄大片一级 | 亚洲国产精品久久久久 | 国产精品欧美久久久久一区二区 |