lintcode 371. 用递归打印数字

2018-09-07  本文已影响10人  cuizixin

难度:中等

1. Description

371. 用递归打印数字

2. Solution

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
上一篇 下一篇

猜你喜欢

热点阅读