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
- 금융문자분석경진대회
- 데이콘
- 우분투
- 캐치카페
- Real or Not? NLP with Disaster Tweets
- 프로그래머스
- PYTHON
- 편스토랑
- leetcode
- 프로그래머스 파이썬
- Git
- 더현대서울 맛집
- ubuntu
- github
- Baekjoon
- Docker
- ChatGPT
- SW Expert Academy
- gs25
- dacon
- 파이썬
- Kaggle
- 맥북
- hackerrank
- programmers
- 자연어처리
- 편스토랑 우승상품
- AI 경진대회
- 코로나19
- 백준
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 263. Ugly Number (Python) 본문
728x90
반응형
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.
Example 1:
Input: 6
Output: true
Explanation: 6 = 2 × 3
Example 2:
Input: 8
Output: true
Explanation: 8 = 2 × 2 × 2
Example 3:
Input: 14
Output: false
Explanation: 14 is not ugly since it includes another prime factor 7.
Note:
- 1 is typically treated as an ugly number.
- Input is within the 32-bit signed integer range: [−231, 231 − 1].
Solution
class Solution:
def isUgly(self, num: int) -> bool:
answer = False
if num <= 0:
return False
nums = [2, 3, 5]
for i in nums:
while num % i == 0:
num = num / i
if num == 1:
answer = True
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1556. Thousand Separator (Python) (0) | 2020.08.29 |
---|---|
[leetCode] 709. To Lower Case (Python) (0) | 2020.08.15 |
[leetCode] 665. Non-decreasing Array (Python) (0) | 2020.08.13 |
[leetCode] 344. Reverse String (Python) (0) | 2020.08.13 |
[leetCode] 121. Best Time to Buy and Sell Stock (Python) (0) | 2020.08.13 |
Comments