Next permutation solution
def next_per(nums):
t=0
if max(nums)==nums[0]:
t=max(nums)
nums[0]=nums[len(nums)-1]
nums[len(nums)-1]=t
return nums
else:
m=max(nums)
t=nums.index(max(nums))
nums[t] = nums[t-1]
nums[t-1]=m
return nums
nums=[1,2,3]
print(next_per(nums))
output = [1,3,2]
Comments
Post a Comment
If you have any doubt you ask me in comment section