mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
19 lines
247 B
Go
19 lines
247 B
Go
package main
|
|
|
|
func lexicalOrder(n int) []int {
|
|
ans := make([]int, n)
|
|
num := 1
|
|
for i := 0; i < n; i++ {
|
|
ans[i] = num
|
|
if num*10 <= n {
|
|
num *= 10
|
|
} else {
|
|
for num%10 == 9 || num+1 > n {
|
|
num /= 10
|
|
}
|
|
num++
|
|
}
|
|
}
|
|
return ans
|
|
}
|