当前位置:网站首页>【LeetCode】728. Self divisor
【LeetCode】728. Self divisor
2022-07-16 07:29:00 【pass night】
subject
Self divisor It refers to the number that can be divided by every digit it contains .
- for example ,
128It's a Self divisor , because128 % 1 == 0,128 % 2 == 0,128 % 8 == 0.
Self divisor Inclusion is not allowed 0 .
Given two integers left and right , Return a list , The elements of the list are ranges [left, right] All of the inside Self divisor .
Example 1:
Input :left = 1, right = 22
Output :[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
Example 2:
Input :left = 47, right = 85
Output :[48,55,66,77]
Tips :
1 <= left <= right <= 104
Ideas
- Define a function , If a natural number contains zero or is divided by its own number of digits without leaving zero, it is not a self divisor , Otherwise it would be
Code
class Solution:
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
res =[]
def isSelfDevidingNumber(n: int):
for i in str(n):
if int(i) ==0 or n % int(i) != 0:
return False
return True
for i in range(left,right+1):
if isSelfDevidingNumber(i): res.append(i)
return res
Complexity
- Time complexity : O ( n ) O(n) O(n)
- Spatial complexity : O ( 1 ) O(1) O(1)
边栏推荐
- Leetcode lecture - 1217 Play chips (difficulty: simple)
- 通俗讲Cookie,Session,Token区别
- Unity3d transform component
- SAP t-code transaction code set (continuously updated)
- 【MySQL】分页查询踩坑
- Basic knowledge of redis - rookie tutorial
- Implementation of binarysearchtree (BST) class template for binary search tree
- 【LeetCode】2024. The most perplexing degree of examination
- Implementation method of three column layout (generally, it is required to write as much as possible)
- 863. All Nodes Distance K in Binary Tree
猜你喜欢

五、Microsoft群集服务(MSCS)环境的搭建实验报告

数据存储与容灾(第2版)主编 鲁先志 武春岭综合训练答案

MySQL - data page

Mise en œuvre du rapport d'expérience RAID logiciel

2、 Implementation of software RAID experiment report

闭包那点事儿

SAP ABAP Smartforms 踩过的坑

AVL tree - binary lookup tree with equilibrium condition

JVM principle and Practice

JVM directory
随机推荐
Week4
2021-11-7bugku做题记录25——POST
通俗讲Cookie,Session,Token区别
Unity foundation to getting started - Navigation
ReentrantLock的公平与非公平核心区别
【LeetCode】2028. Find the missing observation data
Implementation of hash table separation link method class template
SAP ABAP Smartforms 踩过的坑
【6月5号学习记录】
2、 Implementation of software RAID experiment report
SAP DUMP CX_ SY_ CONVERSION_ NO_ NUMBER
Independent game notes-001 the beginning of a world
Title: the nearest common ancestor of binary tree
SAP ABAP Selection Screen 选择屏幕看这一篇就够了(持续更新)
Five principles of aiops landing (3): Architecture route
SAP OPEN SQL
小米举办第五届IoT安全峰会,助力行业安全隐私保护
六、数据备份软件的配置实验报告
SAP Logon 无法正常启动
[learning progress on June 4]