Convert Integer to the Sum of Two No-Zero Integers ( LeetCode ) Problem Solution.
Given an integer n
. No-Zero integer could be a positive integer which does not contain any 0 in its decimal representation.
Return an inventory of two integers
[A, B]
where:A
andB
are No-Zero integers.A + B = n
It's guarateed that there's a minimum of one valid solution. If there are many valid solutions you'll return any of them.
Example 1:
Input: n = 11 Output: [2,9]
Example 2:
Input: n = 10000 Output: [1,9999]
Example 3:
Input: n = 69 Output: [1,68]
Example 4:
Input: n = 1010 Output: [11,999]
Constraints:
2 <= n <= 10^4
Solution:-
class Solution:
def getNoZeroIntegers(self, n: int) -> List[int]:
i=1
while(i<=n):
a=i
b=(n-i)
print(a,"\t",b)
b=str(b)
a=str(a)
if '0' in a:
i+=1
elif '0' in b:
i+=1
else:
b=int(b)
return [a,b]
Runtime: 28 ms, faster than 66.62% of Python3 online submissions for Convert Integer to the Sum of Two No-Zero Integers.
Memory Usage: 14 MB, but 100.00% of Python3 online submissions for Convert Integer to the Sum of Two No-Zero Integers.
0 Comments