LeetCode386 字典序排数
作者:互联网
构造字典树,dfs遍历记录
class Solution:
def lexicalOrder(self, n: int) -> List[int]:
ans = []
def dfs(cur):
if cur <= n:
ans.append(cur)
else:
return
for i in range(10):
dfs(cur * 10 + i)
for i in range(1, 10): dfs(i)
return ans
标签:排数,cur,int,LeetCode386,dfs,字典 来源: https://www.cnblogs.com/solvit/p/16437513.html