Get the App
SLTechnology News&Howtos  ›  Development  › 

How does LeetCode print from 1 to the maximum number of n digits

Shulou Source: shulou.com Published: 2022-06-02 06:35:30 09月28日 Update

This article mainly introduces how LeetCode prints from 1 to the maximum number of n digits, the article is very detailed, has a certain reference value, interested friends must read it!

Topic: enter the number n and print from 1 to the largest n-digit decimal number in order. For example, enter 3, then print 1, 2, 3,., 999

Def printToMaxOfNDigits (n): print 1, 2,..., 99999 (n 9s) can start with 1 and then be added to n 9s by large addition. You can also use the recursive method to implement "" def helper (idx): # Recursive exit is to set the last bit if idx = = n-1: for j in range (n): if number [j]! = '0values: break if number [j] = =' 0entries: Return else: print ('. Join (number [j:])) return for k in range (10): # there are 10 digits available for each bit After the first bit is set, the next bit is set. After setting n bits, number [idx + 1] = str (k) helper (idx + 1) if n < 1: return number = ['0'] * n for i in range (10): # for the first bit There are 10 numbers available number [0] = str (I) helper (0) above is all the contents of the article "how to print from 1 to the largest n digits by LeetCode". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Maximum number digit content article recursion input value interest addition decimal big number guys buddies that is methods more knowledge industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia Linux MySQL Huawei