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