Python | Leetcode Python题解之第386题字典序排数
题目:
题解:
class Solution:
def lexicalOrder(self, n: int) -> List[int]:
ans = [0] * n
num = 1
for i in range(n):
ans[i] = num
if num * 10 <= n:
num *= 10
else:
while num % 10 == 9 or num + 1 > n:
num //= 10
num += 1
return ans