Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1.
Example 1:
Example 2:
解法1:
用next permutation的算法来解,先把n转换成一个数字的数组,然后接下的算法就是一致的了。
要注意的是算出来的答案可能会overflow,所以要判断一下是否overflow。
C++
Java