leetcode 263. Ugly Number
LeetCode number
2023-09-14 09:11:52 时间
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 factor7
.
Note:
1
is typically treated as an ugly number.- Input is within the 32-bit signed integer range: [−231, 231 − 1].
-
class Solution(object): def isUgly(self, num): """ :type num: int :rtype: bool """ # greddy if num <= 0: return False for x in [2, 3, 5]: while num % x == 0: num = num / x return num == 1
相关文章
- <leetcode刷题-数组> 【双指针】旋转数组
- LeetCode 700题 题解答案集合 Python
- 高质量DP压轴,非常精彩的比赛。LeetCode周赛第282场
- LeetCode 617. 合并二叉树
- LeetCode 8. 字符串转换整数 (atoi)
- 用Js刷LeetCode拿offer-经典高频40题
- LeetCode - #69 x 的平方根
- 用javascript分类刷leetcode---动态规划(图文视频讲解)
- LeetCode-279-完全平方数
- EPA认证空气净化器出口美国加州怎么获得EO Number,和establishment number一样吗?
- MySQL Error number: 4007; Symbol: ER_REGEX_NUMBER_TOO_BIG; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-010219; Symbol: ER_UNKNOWN_ERROR_NUMBER; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-02855: Number of requests is less than the number of slaves ORACLE 报错 故障修复 远程处理