Loading

LeetCode - 31. Next Permutation

 31. Next Permutation

Problem's Link

 ----------------------------------------------------------------------------

Mean: 

给定一个数列,求这个数列字典序的下一个排列.

analyse:

next_permutation函数的运用.

Time complexity: O(N)

 

view code

class Solution
{
public:
   void nextPermutation(vector<int>& nums)
   {
       if(next_permutation(nums.begin(),nums.end()))
           return;
       else
       {
           sort(nums.begin(),nums.end());
           return;
       }
   }
};
posted @ 2016-02-20 13:13  北岛知寒  阅读(236)  评论(0编辑  收藏  举报