找到比给定数大的数

Round 5: Q2:
Design an algorithm to find the immediate greater number to a 
given number, such that the result has the same digits as the given input number.
Example:
Input Output
1234 1243
1243 1324

这个题目就是明显找规律的,首先要确定这个数是正是负。


从后往前找,找到第一个下降的数

将这个数和从这个数开始到末尾的数大于这个数的最小值交换值

对从这个位置开始的串从小到大排序


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值