From 46de941e497a5990ee16f7141131c266aa3635a8 Mon Sep 17 00:00:00 2001 From: ductnn Date: Sun, 4 Feb 2024 00:59:13 +0700 Subject: [PATCH] add sol --- .../1291.SequentialDigits/sequentialDigits.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 leetcode/1291.SequentialDigits/sequentialDigits.go diff --git a/leetcode/1291.SequentialDigits/sequentialDigits.go b/leetcode/1291.SequentialDigits/sequentialDigits.go new file mode 100644 index 0000000..2e61c18 --- /dev/null +++ b/leetcode/1291.SequentialDigits/sequentialDigits.go @@ -0,0 +1,30 @@ +// https://leetcode.com/problems/sequential-digits + +package main + +import ( + "fmt" + "sort" +) + +func sequentialDigits(low int, high int) []int { + ans := []int{} + for i := 1; i < 9; i++ { + x := i + for j := i + 1; j < 10; j++ { + x = x*10 + j + if low <= x && x <= high { + ans = append(ans, x) + } + } + } + sort.Ints(ans) + return ans +} + +func main() { + low := 100 + high := 300 + + fmt.Println(sequentialDigits(low, high)) +}