LintCode 52 下一个排列

来源:互联网 发布:西方现代哲学史知乎 编辑:程序博客网 时间:2024/04/30 13:33

题目:nextPermutation


要求:

给定一个整数数组来表示排列,找出其之后的一个排列。

样例:

给出排列[1,3,2,3],其下一个排列是[1,3,3,2]
给出排列[4,3,2,1],其下一个排列是[1,2,3,4]

算法要求:

解题思路:

直接用STL
next_permutation返回下一个排列

算法如下:

    vector<int> nextPermutation(vector<int> &nums) {        // write your code here        next_permutation(nums.begin(), nums.end());        return nums;    }
0 0
原创粉丝点击