EasyNo. 1317

Convert Integer to the Sum of Two No-Zero Integers — LeetCode 1317 Python Solution

Topics
Math
Reading time
2 min

The problem

No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [a, b] where: a and b are No-Zero integers.

Example

Input
n = 2
Output
[1,1]
Explanation
Let a = 1 and b = 1.

Python solution

PythonSolution
class Solution:
    def getNoZeroIntegers(self, n: int) -> List[int]:
        for a in count(1):
            b = n - a
            if "0" not in f"{a}{b}":
                return [a, b]

Complexity

Time
O(n × log n)where n is the integer given in the problem
Space · auxiliary
O(log n)

Pattern: Math and Number Theory

Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.

The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.

Related problems

Related problems
No.ProblemDifficulty
0002Add Two NumbersMedium
0007Reverse IntegerMedium
0009Palindrome NumberEasy
0043Multiply StringsMedium
0048Rotate ImageMedium
0050Pow(x, n)Medium

Frequently asked questions

How hard is LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers?

LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers is rated Easy on LeetCode.

What is the time complexity of LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers?

The Python solution on this page runs in O(n × log n), where n is the integer given in the problem.

What is the space complexity of LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers?

The Python solution on this page uses O(log n) auxiliary space.

What topics does LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers cover?

LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers is tagged Math on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.