# 打印从 1 到最大的 n 位数 class Solution: def Increment(self, number): overFlow = False carry = 0 length = len(number) for i in range(length - 1, -1, -1): num = ord(number[i]) - ord('0') + carry if i == length - 1: num += 1 if num >= 10: if i == 0: overFlow = True else: num -= 10 carry = 1 number[i] = chr(ord('0') + num) else: number[i] = chr(ord('0') + num) break return overFlow def PrintNum(self, number): string = ''.join(number) for i in range(len(string)): if string[i] != '0': print(string[i:]) break def print1ToMaxOfNDigits(self, n): if n >= 0: number = ['0'] * n while not self.Increment(number): self.PrintNum(number) 主要是 Icreament 中的 for 循环小弟看不太懂,不懂的地方在于如何满十的时候进一个位,我比较笨,有时候绕不过来了,希望各位懂的大哥们帮帮忙,如果能得到对 Icreament 这段代码的说明就真的非常感谢了。
