Depth-First Search
386. Lexicographical Numbers
List 1..n in lexicographical (dictionary-string) order — 1, 10, 11, …, 19, 2, 20, … — in O(n) time without materialising and sorting strings. The trick is to see the structure hiding underneath:…
Loading…