题目描述:
自己的提交:
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)
原文:https://www.cnblogs.com/oldby/p/12091330.html