import itertools
def aa(num: int):
x=eval(‘9’*len(str(num)))
for i in itertools.permutations(str(num), len(str(num))):
j=eval(’’.join(i))
x=j if num<j<x else x
return x if x != eval(‘9’*len(str(num))) else None
def bb(num: int):
s=
for i in itertools.permutations(str(num), len(str(num))):
s.append(eval(’’.join(i)))
s=sorted(list(set(s)))
return s[s.index(num)+1] if s.index(num) < len(s)-1 else None
def next_bigger(n) -> int:
n = int(n)
new_num = []
for i in range(len(str(n))):
a = n % 10
n = n // 10
if(len(new_num)>=1):
c = new_num[-1]
if a < c:
d = min(filter(lambda x:x>a and x <=c,new_num))
new_num[new_num.index(d)] = a
a = d
new_num.sort()
return int(str(n) + str(a) + "".join([str(x) for x in new_num]))
new_num.append(a)
else:
return -1
assert next_bigger(12) == 21
assert next_bigger(513) == 531
assert next_bigger(2017) == 2071
assert next_bigger(414) == 441
assert next_bigger(144) == 414
from itertools import permutations
def next_bigger(n):
length = len(str(n))
if length > 1:
s = [i for i in str(n)]
datas = list(permutations(s,length))
results = list(set([int(''.join(x)) for x in datas]))
results.sort()
if results[-1] == n:
return -1
return results[results.index(n)+1]
else:
return -1
def next_bigger(n: int)->int :
new_list=[]
for i in itertools.permutations(str(n),len(str(n))):
if int(''.join(i)) not in new_list:new_list.append(int(''.join(i)))
new_list.sort()
return new_list[new_list.index(n)+1]
from itertools import permutations
def next_bigger(n: int) -> int:
premutation_values=[]
for i in permutations(str(n)):
if int(''.join(i)) not in premutation_values:
premutation_values.append(int(''.join(i)))
premutation_values.sort()
return premutation_values[premutation_values.index(n)+1]
assert next_bigger(3542)==4235
def next_bigger(n: int) -> int:
s=[]
from itertools import permutations
n_list=[k for k in str(n)]
for i in permutations(n_list,len(n_list)):
s.append(int(''.join(i)))
s.sort(reverse=True)
for j in range(len(s)):
if s[j]==n:
return s[j-1]
assert next_bigger(12) == 21
assert next_bigger(513) == 531
assert next_bigger(2017) == 2071
assert next_bigger(414) == 441
assert next_bigger(144) == 414