首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >LeetCode 0031 - Next Permutation

LeetCode 0031 - Next Permutation

作者头像
Reck Zhang
发布于 2021-08-11 10:33:14
发布于 2021-08-11 10:33:14
3740
举报
文章被收录于专栏:Reck ZhangReck Zhang

Next Permutation

Desicription

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

Solution

代码语言:javascript
复制
class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        next_permutation(nums.begin(), nums.end());
    }
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-11-11,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • Next Permutation
    • Desicription
    • Solution
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档