找到比给定数大的数
| 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 |
這個題目就是明顯找規律的,首先要確定這個數是正是負。
從后往前找,找到第一個下降的數
將這個數和從這個數開始到末尾的數大于這個數的最小值交換值
對從這個位置開始的串從小到大排序
總結
- 上一篇: 找单独出现的bit 数组
- 下一篇: 打印数字回文