leetcode-167周赛-1291-顺次数
题目描述:

自己的提交:
class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
l,h = len(str(low)),len(str(high))
res = []
def helper(num,length):
if length == 0 and low <= num <= high:
res.append(num)
return
if num % 10 == 9:
return
helper(num*10+(num%10+1),length-1)
for i in range(l,h+1):
for j in range(1,10):
helper(j,i-1)
return res
另:
class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
ans = list()
for i in range(1, 10):
num = i
for j in range(i + 1, 10):
num = num * 10 + j
if low <= num <= high:
ans.append(num)
return sorted(ans)
leetcode-167周赛-1291-顺次数的更多相关文章
- LeetCode 1291. 顺次数
地址 https://leetcode-cn.com/problems/sequential-digits/submissions/ 题目描述我们定义「顺次数」为:每一位上的数字都比前一位上的数字大 ...
- 【Leetcode 滑动窗口】顺次数(1291)
题目 我们定义「顺次数」为:每一位上的数字都比前一位上的数字大 1 的整数. 请你返回由 [low, high] 范围内所有顺次数组成的 有序 列表(从小到大排序). 示例 1: 输出:low = ...
- leetcode 167 two sum II
167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascendi ...
- [LeetCode] #167# Two Sum II : 数组/二分查找/双指针
一. 题目 1. Two Sum II Given an array of integers that is already sorted in ascending order, find two n ...
- 29. leetcode 167. Two Sum II - Input array is sorted
167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascendi ...
- LeetCode 167. Two Sum II - Input array is sorted (两数之和之二 - 输入的是有序数组)
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 力扣(LeetCode)453. 最小移动次数使数组元素相等
给定一个长度为 n 的非空整数数组,找到让数组所有元素相等的最小移动次数.每次移动可以使 n - 1 个元素增加 1. 示例: 输入: [1,2,3] 输出: 3 解释: 只需要3次移动(注意每次移动 ...
- leetcode 双周赛9 进击的骑士
一个坐标可以从 -infinity 延伸到 +infinity 的 无限大的 棋盘上,你的 骑士 驻扎在坐标为 [0, 0] 的方格里. 骑士的走法和中国象棋中的马相似,走 “日” 字:即先向左(或右 ...
- LeetCode 167:两数之和 II - 输入有序数组 Two Sum II - Input array is sorted
公众号: 爱写bug(ID:icodebugs) 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index ...
- [LeetCode] 167. Two Sum II - Input array is sorted 两数和 II - 输入是有序的数组
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
随机推荐
- DHCP服务器怎么设置怎么启动
DHCP:动态主机配置协议,服务器用于为网络中的客户端自动分配IP地址.这种方法避免了由于手动配置IP地址导致的IP地址冲突问题,同时也减少了网络管理员的工作量. 工具/原料 在配置DHCP服务器时, ...
- 奖项-MVP:MVP(微软最有价值专家)百科
ylbtech-奖项-MVP:MVP(微软最有价值专家)百科 微软最有价值专家(MVP) 是指具备一种或多种微软技术专业知识,并且积极参与在线或离线的社群活动,经常与其他专业人士分享知识和专业技能,受 ...
- CSS-同一行的元素高度统一
一:flex 大法 步骤 设置外部容器 display: flex; 设置内部容器 align-items: stretch; 原理 https://developer.mozilla.org/zh- ...
- JS-生成器函数(function 星号)的暂停和恢复(yield)
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/function* https://devel ...
- JavaScript中的十种操作符
① 一元操作符(参与的只有一个变量) 前置递增递减(语句解析到递增/递减时值就被改变了) 后置递增递减(整个语句执行后值再改变) 递增递减也可用于字符串,布尔值,对象等,结果都将是数值: ;v ...
- HTTP 协议解析
目录 目录 HTTP 协议 HTTP 协议工作原理 HTTP Request 请求行 Request Header HTTP Response 状态行 Response Header Body HTT ...
- 【python】含中文字符串截断
对于含多字节的字符串,进行截断的时候,要判断截断处是几字节字符,不能将多字节从中分割,避免截断后乱码 下面给出utf8和gb18030上的实现, 用任何一种都可以,可以先进行转码,用encode, d ...
- vsphere虚拟化之 NTP服务的创建(三)
1.先修改windows 2012的注册表. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\ 设置 Annou ...
- 【xinsir】githook之precommit分享
钩子类型 使用node编写githook,以pre-commit为例: 1.在项目下配置自动生成pre-commit文件,一般可以在启动项目的脚本下添加: modifyPreCommit: funct ...
- Python_pickle
pickle是一个可以将任意一个对象存储在硬盘文件中的工具. 更新:Python3中用法变了: https://www.cnblogs.com/fmgao-technology/p/9078918. ...