From d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa Mon Sep 17 00:00:00 2001
From: jack <0x6A73@pm.me>
Date: Fri, 14 Jun 2024 13:13:15 -0600
Subject: initial

---
 sequential_digits.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 sequential_digits.py

(limited to 'sequential_digits.py')

diff --git a/sequential_digits.py b/sequential_digits.py
new file mode 100644
index 0000000..f84dfcc
--- /dev/null
+++ b/sequential_digits.py
@@ -0,0 +1,32 @@
+# 1291. Sequential Digits
+
+"""
+an integer has sequential digits if and only if each digit in the number is
+one more than the previous digit. return a sorted list of all the integers in
+the range '[low, high]' inclusive that have sequential digits.
+"""
+
+
+class Solution(object):
+    def sequentialDigits(self, low, high):
+        """
+        :type low: int
+        :type high: int
+        :rtype: List[int]
+        """
+        ans = []
+        queue = deque(range(1, 10))
+        while queue:
+            idx = queue.popleft()
+            if low <= idx <= high:
+                ans.append(idx)
+            last = idx % 10
+            if last < 9:
+                queue.append(idx * 10 + last + 1)
+        return ans
+
+
+if __name__ == "__main__":
+    obj = Solution()
+    print(obj.sequentialDigits(low=100, high=300))
+    print(obj.sequentialDigits(low=1000, high=13000))
-- 
cgit v1.2.3