【leetcode】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.Example 1:
Input: low = 100, high = 300
Output: [123,234]Example 2:
Input: low = 1000, high = 13000
Output: [1234,2345,3456,4567,5678,6789,12345]Constraints:
10 <= low <= high <= 10^9
解题思路:和 【leetcode】1215.Stepping Numbers 思路是一样的,利用BFS的思想,把所有符合条件的数字找出来。
代码如下:
class Solution(object):
def sequentialDigits(self, low, high):
"""
:type low: int
:type high: int
:rtype: List[int]
"""
res = []
queue = range(1,10)
while len(queue) > 0:
val = queue.pop(0)
if val >= low and val <= high:
res.append(val)
elif val > high:
continue
last = int(str(val)[-1])
if last == 9:continue
new_val = str(val) + str(last + 1)
queue.append(int(new_val))
return sorted(res)
【leetcode】1291. Sequential Digits的更多相关文章
- 【LeetCode】 258. Add Digits 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:减1模9 方法三:直接模9 日 ...
- 【LeetCode】258. Add Digits (2 solutions)
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- 【LeetCode】258. Add Digits
题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...
- 【leetcode】Monotone Increasing Digits
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- 【LeetCode】788. Rotated Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)
[LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...
- 【LeetCode】402. Remove K Digits 解题报告(Python)
[LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- 【LeetCode】423. Reconstruct Original Digits from English 解题报告(Python)
[LeetCode]423. Reconstruct Original Digits from English 解题报告(Python) 标签: LeetCode 题目地址:https://leetc ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
随机推荐
- 飞腾1500A 上面银河麒麟操作系统 进行远程以及添加用户的方法 linux xrdp
1. 安装远程用的软件: sudo apt-get install xrdp vnc4server xbase-clients systemctl enable xrdp systemctl star ...
- SQL SERVER 根据字段名称批量设置为主键
--设置主键 --alter table 你的表名 add constraint pk_s primary key (id) SELECT 'alter table ' + TABLE_NAME + ...
- Spark Scala当中reduceByKey(_+_) reduceByKey((x,y) => x+y)的用法
[学习笔记] reduceByKey(_+_)是reduceByKey((x,y) => x+y)的一个 简洁的形式*/ val rdd08 = sc.parallelize(List((1, ...
- Ubuntu18突然卡死解决方法
emmmm 1.Ctrl+Alt+F2/F3/F4/F5/F6 F2-6随便选一个都可以 2.进入tty终端后先输入用户名和密码(记得小键盘会自动
- Windows32或64位下载安装配置Spark
[学习笔记] Windows 32或64位下载安装配置Spark:1)下载地址:http://spark.apache.org/downloads.html 马克-to-win @ 马克java社区: ...
- extra bytes at beginning or within zipfile
主要用文本文档打开看看是否带有#!/bin/bash 修改pom文件<executable>false</executable>
- 作业1:java虚拟机内存模型图示
看了很多篇文章,整理成一幅图,但仍然有许多不解的地方,以后再接着完善,哪位大神看到不正确的地方,请指出,谢谢.
- Docker 杂记
1.配置阿里云加速 :可以找到各种加速URL.比如 https://tnxkcso1.mirror.aliyuncs.com/ 2.windows 配置: 3.docker info可以看到新的配置已 ...
- linux - 卸载python
2019年10月15日12:05:42 [root@spider1 bin]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制 ...
- Oracle学习笔记:rank、dense_rank、row_number、ntile等排序算法
在 oracle 中有很多函数可以实现排序的功能,但是不尽相同.下面一一解说. row_number函数 功能:可实现分组排序,为数据行添加序号,多用于分页查询. 语法:row_number() ov ...