Convert Integer to the Sum of Two No-Zero Integers — LeetCode 1317 Python Solution
- Problem
- #1317
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
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
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
| Measure | Complexity |
|---|---|
| Time | O(n \times \log n), where n is the integer given in the problem |
| Space | O(\log n) auxiliary |
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
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 \times \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.