2025-08-02 15:14:37 +0000 UTC

Convert Integer to the Sum of Two No-Zero Integers

Code

class Solution:
    def getNoZeroIntegers(self, n: int) -> List[int]:
        if n <= 10:
            return [1, n - 1]
        def check(num: int) -> bool:
            while num > 0:
                if num % 10 == 0:
                    return False
                num //= 10
            return True
        for i in range(1, (n + 1) // 2):
            num1, num2 = i, n - i
            if check(num1) and check(num2):
                return [num1, num2]
        raise Exception