Please solve the programming task below using a self-contained code snippet in a markdown code block.

Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.
You must write an algorithm that runs in O(n) time and uses O(1) extra space. 
 
Please complete the following python code precisely:
```python
class Solution:
    def lexicalOrder(self, n: int) -> List[int]:
```