其他分享
首页 > 其他分享> > LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers (Easy)

LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers (Easy)

作者:互联网

Given an integer n. No-Zero integer is a positive integer which doesn't contain any 0 in its decimal representation.

Return a list of two integers [A, B] where:

It's guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.

 

Method: 暴力解法

Time: O(n) 

Space: O(1)

class Solution:
    def getNoZeroIntegers(self, n: int) -> List[int]:
        
        a = 1 
        b = n - a 
        
        while a <= b:
            if '0' in str(a) or '0' in str(b):
                a += 1 
                b -= 1 
            else:
                break 
        return [a, b]

标签:1317,Integers,Convert,No,int,there,Zero,integer,any
来源: https://www.cnblogs.com/sky37/p/13923868.html