386. Lexicographical Numbers
2016-09-22 本文已影响0人
阿团相信梦想都能实现
class Solution(object):
def lexicalOrder(self, n):
"""
:type n: int
:rtype: List[int]
"""
#comments are based on counting to 150
res=[1]
while len(res)<n:
new=res[-1]*10 #add 1,10,100
while new>n:#loop through numbers such as 101-109
new/=10
new+=1
while new%10==0: #increase the base from 10 to 11
new/=10
res.append(new)
return res