Leetcode 1317.将整数转换为两个无零整数的和(Convert Integer to the Sum of Two No-Zero Integers)

    技术2022-07-11  116

    Leetcode 1317.将整数转换为两个无零整数的和

    1 题目描述(Leetcode题目链接)

      「无零整数」是十进制表示中 不含任何 0 的正整数。

    给你一个整数 n,请你返回一个 由两个整数组成的列表 [A, B],满足:

    A 和 B 都是无零整数A + B = n题目数据保证至少有一个有效的解决方案。

    如果存在多个有效解决方案,你可以返回其中任意一个。

    输入:n = 2 输出:[1,1] 解释:A = 1, B = 1. A + B = n 并且 A 和 B 的十进制表示形式都不包含任何 0

    提示:2 <= n <= 10^4

    2 题解

      随机取值

    class Solution: def getNoZeroIntegers(self, n: int) -> List[int]: while 1: i = random.randint(1, n) j = n - i if "0" not in str(i) + str(j): return [i, j]
    Processed: 0.011, SQL: 9