386. Lexicographical Numbers Medium

@problem@discussion
#Depth-First Search#Trie



1/**
2 * [386] Lexicographical Numbers
3 *
4 * Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.
5 * You must write an algorithm that runs in O(n) time and uses O(1) extra space. 
6 *  
7 * Example 1:
8 * Input: n = 13
9 * Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]
10 * Example 2:
11 * Input: n = 2
12 * Output: [1,2]
13 *  
14 * Constraints:
15 * 
16 * 	1 <= n <= 5 * 10^4
17 * 
18 */
19pub struct Solution {}
20
21// problem: https://leetcode.com/problems/lexicographical-numbers/
22// discuss: https://leetcode.com/problems/lexicographical-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
23
24// submission codes start here
25
26impl Solution {
27    pub fn lexical_order(n: i32) -> Vec<i32> {
28        vec![]
29    }
30}
31
32// submission codes end
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_386() {
40    }
41}
42


Back
© 2025 bowen.ge All Rights Reserved.