Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- SW Expert Academy
- 백준
- 캐치카페
- 코로나19
- AI 경진대회
- PYTHON
- github
- Real or Not? NLP with Disaster Tweets
- 우분투
- Docker
- 자연어처리
- 편스토랑
- Kaggle
- ChatGPT
- 금융문자분석경진대회
- hackerrank
- 파이썬
- 데이콘
- leetcode
- 편스토랑 우승상품
- 프로그래머스
- 프로그래머스 파이썬
- ubuntu
- 맥북
- Git
- dacon
- 더현대서울 맛집
- programmers
- Baekjoon
- gs25
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 728. Self Dividing Numbers (Python) 본문
728x90
반응형
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.
Solution
class Solution:
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
answer = [num for num in range(left, right+1) if '0' not in str(num)]
answer = [num for num in answer if 0 not in [num % int(n) == 0 for n in str(num)]]
return answer
class Solution:
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
answer = [num for num in range(left, right+1) if '0' not in str(num) and all([num % int(n) == 0 for n in str(num)])]
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 443. String Compression (Python) (0) | 2020.09.03 |
---|---|
[leetCode] 1480. Running Sum of 1d Array (Python) (0) | 2020.09.02 |
[leetCode] 977. Squares of a Sorted Array (Python) (0) | 2020.09.01 |
[leetCode] 1281. Subtract the Product and Sum of Digits of an Integer (Python) (0) | 2020.08.30 |
[leetCode] 1556. Thousand Separator (Python) (0) | 2020.08.29 |
Comments