刷一题Leetcode:Ugly Number
2015-09-05 21:00
429 查看
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
For example,
not ugly since it includes another prime factor
Note that
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
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.
public class Solution { public boolean isUgly(int num) { if (num < 1) { return false; } else if (num == 1) { return true; } else if (num % 3 == 0) { num = num / 3; return isUgly(num); } else if (num % 5 == 0) { num = num / 5; return isUgly(num); } else if (num % 2 == 0) { num = num / 2; return isUgly(num); } else { return false; } } }
相关文章推荐
- 使用<input type="file">实现文件上传
- Direct-X学习笔记--骨骼动画进阶
- Spring MVC学习
- [LeetCode] Search a 2D Matrix
- 关于VS2010 C#使用DirectX的问题[英]
- C++技术点积累(1)
- (1.4.6.2)中位数
- 1008. 数组元素循环右移问题 (20)
- vim
- hdu5427(BestCoder Round #54 (div.2)1001题)
- 混合编程杂谈续——发布
- Varnish实现Web缓存
- 【C++】嵌套类、友元
- 常见的链表面试题大汇总:
- Android实践——密码本SecretBook
- VC commands and tools
- 1.居家环境参数监测系统介绍
- web开发与正则表达式
- 实现购物结算功能
- Android四种Activity的加载模式(转)