<p>You are given an integer <code>num</code>. You can swap two digits at most once to get the maximum valued number.</p>

<p>Return <em>the maximum valued number you can get</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> num = 2736
<strong>Output:</strong> 7236
<strong>Explanation:</strong> Swap the number 2 and the number 7.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> num = 9973
<strong>Output:</strong> 9973
<strong>Explanation:</strong> No swap.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= num &lt;= 10<sup>8</sup></code></li>
</ul>

class Solution:
    def maximumSwap(self, num):
        # Convert the number to a list of digits
        digits = list(str(num))
        
        # Traverse the list of digits
        for i in range(len(digits)):
            # Find the largest digit to swap with the current digit
            max_digit = digits[i]
            max_idx = i
            for j in range(len(digits)-1, i, -1):
                # We want the largest digit and it should appear later in the number
                if digits[j] > max_digit:
                    max_digit = digits[j]
                    max_idx = j
            
            # If we found a larger digit that appears later, swap and return the result
            if max_digit != digits[i]:
                digits[i], digits[max_idx] = digits[max_idx], digits[i]
                return int("".join(digits))
        
        # If no swap happens, return the original number
        return num


            
16300