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:

  • A and B are No-Zero integers.
  • A + B = n

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]
上一篇:idea中maven在install时出现一个问题


下一篇:经典英文歌