From 8c1fa0daec183d897b8a749b405b83ba91d42842 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Sun, 7 Sep 2025 23:48:05 -0600 Subject: 1317. convert integer to the sum of two no-zero integers --- convert_int_sum_two_int.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 convert_int_sum_two_int.py (limited to 'convert_int_sum_two_int.py') 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)) -- cgit v1.2.3