She*_*500 5 python algorithm math
我在Codewars上遇到了这个挑战:https ://www.codewars.com/kata/next-smaller-number-with-the-same-digits
它接受一个非常大的整数。并返回具有相同数字的下一个最小整数,-1如果不存在则返回。我尝试用蛮力尝试此操作,找到所有排列并找到最接近的排列。这显然效率不高,并导致超时。
-1
什么是有效的方法?
use*_*109 6
例如:
1262347 // original number ^ ^ X Y 1242367 // after the swap ^ ^ Y X 1247632 // after sorting digits to the right of Y ^ Y
归档时间:
6 年,10 月 前
查看次数:
94 次
最近记录: