Back to photostream

Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution

The problem Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution asked us to partition the given integer. We should partition the given integer into two numbers. There is a constraint imposed on these two integers. These two integers should not contain the digit 0. For a better understanding, we will take a look at a few examples.

 

n = 2

 

Explanation: The two integers in the output are 1 and 1. The integers can be the same but they must not have digit 0. The constraint is met in the output. The sum of both the integers is also equal to the input. Thus the output is correct.

n = 1010

 

Explanation: The output is correct because the sum of both the integers is equal to 1010. And they also do not have any digit equal to 0.

Approach for Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution

The problem asked us to partition the given input into two integers. The condition which should be met is already stated in the description above. The first condition is that the sum of the integers must be equal to the given integer. The two integers that will be returned as the output should not contain any 0 digits. To solve the problem, we run a loop over the first integer that ranges from 1 to n. The second integer can be deduced from the first relation. Then we check if both the integers satisfy the second condition.

 

For checking the second condition, we create a custom function that takes an integer as input.

 

www.tutorialcup.com/leetcode-solutions/convert-integer-to...

16 views
0 faves
0 comments
Uploaded on September 3, 2021