Leetcode 1448 Solution

This article provides solution to leetcode question 1448 (maximum-69-number)

https://leetcode.com/problems/maximum-69-number

Solution

class Solution:
    def maximum69Number (self, num: int) -> int:
        y = 1
        last_y = None

        while y <= num:
            if (num // y) % 10 == 6:
                last_y = y
            y *= 10

        return num + last_y * 9 - last_y * 6 if last_y else num