class Solution(object):
    def nextGreaterElement(self, n):
        """
        :type n: int
        :rtype: int
        """
        s = str(n)
        for i, n in enumerate(reversed(s[:-1]), 1):
            if n < s[-i]:
                x, j = min((x, k) for k, x in enumerate(s[-i:]) if x > n)
                ans = s[:-i - 1]
                ans += x
                l = list(s[-i:])
                l[j] = n
                ans += ''.join(sorted(l))
                ans = int(ans)
                if ans >= 1 << 31:
                    return -1
                return ans
        else:
            return -1

Add py solution for 556. Next Greater Element III
Add py solution for 556. Next Greater Element III

556. Next Greater Element III: https://leetcode.com/problems/next-greater-element-iii/

Approach:
    Observe the first item remaining in each step. The value will be added
    1 << step either the remaining count is odd or it's a left-to-right
    step. Hence the n | 0x55555.. is the key.
