lintcode 371. 用递归打印数字

难度:中等

1. Description

lintcode 371. 用递归打印数字_第1张图片
371. 用递归打印数字

2. Solution

  • python
class Solution:
    """
    @param n: An integer
    @return: An array storing 1 to the largest number with n digits.
    """
    def numbersByRecursion(self, n):
        # write your code here
        if n==0:
            return []
        if n==1:
            return [1,2,3,4,5,6,7,8,9]
        tmp = self.numbersByRecursion(n-1)
        ans = []
        ans.extend(tmp)
        for i in range(10**(n-1),10**n):
            ans.append(i)
        return ans

3. Reference

  1. https://www.lintcode.com/problem/print-numbers-by-recursion/description?_from=ladder

你可能感兴趣的:(lintcode 371. 用递归打印数字)