diff options
author | Jack Sangdahl <[email protected]> | 2025-09-07 23:48:05 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-09-07 23:48:05 -0600 |
commit | 8c1fa0daec183d897b8a749b405b83ba91d42842 (patch) | |
tree | f263e4f10705ba6a4d40d3a0dbd151e567edb98a /convert_int_sum_two_int.py | |
parent | e70ec56060a9085a0847d3014c5aecdb0298830a (diff) | |
download | leetcode-8c1fa0daec183d897b8a749b405b83ba91d42842.tar.gz leetcode-8c1fa0daec183d897b8a749b405b83ba91d42842.zip |
1317. convert integer to the sum of two no-zero integers
Diffstat (limited to 'convert_int_sum_two_int.py')
-rw-r--r-- | convert_int_sum_two_int.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/convert_int_sum_two_int.py b/convert_int_sum_two_int.py new file mode 100644 index 0000000..6029ed4 --- /dev/null +++ b/convert_int_sum_two_int.py @@ -0,0 +1,30 @@ +# 1317. Convert Integer to the Sum of Two No-Zero Integers + +""" +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 and 'a + b = n'. the test +cases are generated such that there is at lease one valid solution. if there +are many valid solutions, you can return any of them +""" + + +class Solution(object): + def check(self, n): + return "0" not in str(n) + + def getNoZeroIntegers(self, n): + """ + :type n: int + :rtype: List[int] + """ + for i in range(1, n): + j = n - i + if self.check(i) and self.check(j): + return [i, j] + + +if __name__ == "__main__": + obj = Solution() + print(obj.getNoZeroIntegers(2)) + print(obj.getNoZeroIntegers(11)) |