P18044 [GeeksforGeeks] Next higher number in one swap1703
普及
题目描述

Given a non-negative number num in the form of string. The task is to apply at most one swap operation on the number num so that the result is the next higher number.
Example 1:
Input: num = "768"
Output: "786"
Explanation: This is next higher
number that we can get.
Example 2:
Input: num = "333"
Output: "-1"
Explanation: There is no higher
number than 333.
Your Task:
You don't need to read input or print anything. Your task is to complete the function nxtHighUsingAtMostOneSwap() which takes the string num as inputs and returns the answer.
Expected Time Complexity: O(|num|)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ |num| ≤ 10^{5}
|num| denotes the length of the string num.

输入格式

见题面

输出格式

见题面

样例输入
num = "768"
样例输出
"786"