首页 > 其他 > 详细

leetcode-167周赛-1291-顺次数

时间:2019-12-24 16:01:27      阅读:89      评论:0      收藏:0      [点我收藏+]

题目描述:

技术分享图片

 

 自己的提交:

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-顺次数

原文:https://www.cnblogs.com/oldby/p/12091330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!