0386. Lexicographical Numbers
https://leetcode.com/problems/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 in O(n)
time and uses O(1)
extra space.
Example 1:
Example 2:
Constraints:
1 <= n <= 5 * 104
ac
It's more like a tricky math problem instead of practical algorithm problem.
https://leetcode.com/problems/lexicographical-numbers/discuss/86231/Simple-Java-DFS-Solution
Last updated