I think my solution is one of the optimal solutions. However, it always gets TLE.

```
class Solution(object):
def lexicalOrder(self, n):
"""
:type n: int
:rtype: List[int]
"""
answer = []
for i in range(1, 10):
if i <= n:
self.helper(i, answer, n)
return answer
def helper(self, num, answer, n):
answer.append(num)
for i in range(0, 10):
if num*10+i <= n:
self.helper(num*10+i, answer, n)
```