C++ easy solution ,easy to understand


#1

vector Solution::nextPermutation(vector &nums) {

int breakp=-1;
    int n=nums.size();
    for(int i=n-1;i>0;i--)
    {
        if(nums[i]>nums[i-1])
        {
            breakp=i-1;
            break;
        }
    }
    if(breakp==-1)
    {
        reverse(nums.begin(),nums.end());
        return nums;
        
    }
    for(int i=n-1;i>=0;i--)
    {
        if(nums[i]>nums[breakp])
        {
            swap(nums[i],nums[breakp]);
            reverse(nums.begin()+breakp+1,nums.end());
            break;
        }
        
        
    }
    return nums;

}