386. Lexicographical Numbers
Description
Given an integer n
, return all the numbers in the range [1, n]
sorted in lexicographical order.
You must write an algorithm that runs inO(n)
time and uses O(1)
extra space.
Example 1:
1 | Input: n = 13 |
Example 2:
1 | Input: n = 2 |
Constraints:
1 <= n <= 5 * 10^4
Hints/Notes
- 2025/02/02 Q1
- dfs
- Leetcode solution(checked)
Solution
Language: C++
1 | class Solution { |