Ugly Number (Leet Code)
2015-08-31 09:03
281 查看
Ugly Number
Total Accepted: 9440 TotalSubmissions: 30874
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.
For example,
6, 8are ugly while
14is
not ugly since it includes another prime factor
7.
Note that
1is typically treated
as an ugly number.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
code:
class Solution { public: bool isUgly(int num) { if(num==1) return true; if(num==0) return false; if(num%2==0&&isUgly(num/2)) return true; if(num%3==0&&isUgly(num/3)) return true; if(num%5==0&&isUgly(num/5)) return true; return false; } };
相关文章推荐
- Android autotest - Monkey tool
- 汉明码
- 函数递归计算斐波那契数列前40项和
- 函数递归计算斐波那契数列前40项和
- 排列组合问题-母函数
- 牢记这次的目的
- json 数组 转bean
- 网站制作需要做的
- Social Emotional Computing
- HTML-字体逐渐显示
- 问题:ExecuteNonQuery 与 ExecuteScalar 结果: ExecuteNonQuery方法和ExecuteScalar方法的区别
- 对Oracle 、SQL Server、MySQL、PostgreSQL数据库优缺点分析
- 创建Python虚拟环境---Virtualenv
- 学习Qt5(2)
- 程序员学英语--打开另一个世界的钥匙
- 模仿手机qq的消息控制,Dialog实现
- ROS电子书及相关资料全集
- Leetcode #37 Sudoku Solver
- C的xml编程-libxml2(函数总结篇) http://blog.sina.com.cn/s/blog_6a1837e90100ns9j.html
- Java基础知识强化11:多态的两道基础题