Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.
Example 1: Input: 2736 Output: 7236 Explanation: Swap the number 2 and the number 7. Example 2: Input: 9973 Output: 9973 Explanation: No swap. Note: The given number is in the range [0, 10^8]
int k = t.size() - 1; while(k >= 0) { auto max = max_element(t.begin(),t.begin() + k + 1); if (*max != t[k]) { int a = *max; *max = t[k]; t[k] = a; break; } k--; }
for(auto it = t.rbegin();it != t.rend();it++) { num = 10 * num + *it; } return num; }