[LeetCode&Python] Problem 728. Self Dividing Numbers
2024-09-21 14:00:11
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0
, 128 % 2 == 0
, and 128 % 8 == 0
.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.
Example 1:
Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
Note:
- The boundaries of each input argument are
1 <= left <= right <= 10000
.
Brute-Force!!!
class Solution:
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
result=[] for num in range(left, right+1):
strnum=str(num) flag=True for digit in strnum:
if digit=='0':
flag=False
break if num%int(digit) !=0:
flag=False
break if flag:
result.append(num) return result
最新文章
- 基于类的命令行notebook的实现
- 疯狂房价";逼死";年轻人,别指望中国未来能出人才了
- 有关struts2中用到 js 总结
- jQuery带遮罩层弹窗实现(附源码)
- 让你的 Node.js 应用跑得更快的 10 个技巧(转)
- 各种好用的工具之一 ---- PNGGauntlet
- Android 主题动态切换框架:Prism
- B - Network - uva 315(求割点)
- 去除html页面中按钮在ios中的默认样式,去除select自带的小三角图标
- [Android阅读代码]android-async-http源码学习一
- !important的理解
- 深入学习Java8 Lambda (default method, lambda, function reference, java.util.function 包)
- Java消息队列——JMS概述
- Zookeeper安装及运行
- Notepad++ 中使用tail -f功能
- HTML 样式兼容不同设备类型
- hibernate Validator 6.X 的学习,bean的约束(主要包括的是容器元素的验证)
- document.visibilityState 监听浏览器最小化
- CF 166E Tetrahedron
- Android开发高级进阶——多进程间通信