Skip to content

Commit e8a8e27

Browse files
authored
Update convert-integer-to-the-sum-of-two-no-zero-integers.py
1 parent 5af6587 commit e8a8e27

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Python/convert-integer-to-the-sum-of-two-no-zero-integers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# Time: O(logn)
2-
# Space: O(logn)
2+
# Space: O(1)
33

44
class Solution(object):
55
def getNoZeroIntegers(self, n):
66
"""
77
:type n: int
88
:rtype: List[int]
99
"""
10-
curr, digits = n, []
10+
a, curr, base = 0, n, 1
1111
while curr:
1212
if curr % 10 == 0 or (curr % 10 == 1 and curr != 1):
13-
digits.append('2')
13+
a += base
1414
curr -= 10 # carry
15-
else:
16-
digits.append('1')
15+
a += base
16+
base *= 10
1717
curr //= 10
18-
digits.reverse()
19-
a = int("".join(digits))
2018
return [a, n-a]
2119

2220

0 commit comments

Comments
 (0)