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 |
这个题目就是明显找规律的,首先要确定这个数是正是负。
从后往前找,找到第一个下降的数
将这个数和从这个数开始到末尾的数大于这个数的最小值交换值
对从这个位置开始的串从小到大排序