human
Solve in Python:
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, 108]
 What is a the Python program you requested?
assistant
#Here is the Python program you requested.

class Solution:
     def maximumSwap(self, num):
         arr = [int(c) for c in str(num)]
         n = len(arr)
         posmax = [0] * n
         posmax[-1] = n-1
         for i in range(n-2, -1, -1):
             if arr[i] > arr[posmax[i+1]]:
                 posmax[i] = i
             else:
                 posmax[i] = posmax[i+1]
         for i in range(n):
             if arr[i] == 9:
                 continue
             j = posmax[i]
             if arr[j] > arr[i]:
                 arr[i], arr[j] = arr[j], arr[i]
                 return int(''.join(map(str, arr)))
         return num