def nextPermutation(self, nums):
    found = False
    i = (len(nums) - 2)
    while (i >= 0):
        if (nums[i] < nums[(i + 1)]):
            found = True
            break
        i -= 1
    if (not found):
        nums.sort()
    else:
        m = self.findMaxIndex((i + 1), nums, nums[i])
        (nums[i], nums[m]) = (nums[m], nums[i])
        nums[(i + 1):] = nums[(i + 1):][::(- 1)]
    return nums
def nextPermutation(self, nums):
    found = False
    i = (len(nums) - 2)
    while (i >= 0):
        if (nums[i] < nums[(i + 1)]):
            found = True
            break
        i -= 1
    if (not found):
        nums.sort()
    else:
        m = self.findMaxIndex((i + 1), nums, nums[i])
        (nums[i], nums[m]) = (nums[m], nums[i])
        nums[(i + 1):] = nums[(i + 1):][::(- 1)]
    return nums