LeetCode——Ugly Number
2015-09-26 21:05
381 查看
Description:
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
Note that
寻找丑数:
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.
寻找丑数:
public class Solution { public boolean isUgly(int num) { if(num <= 0) { return false; } while(num % 2 == 0) { num /= 2; } while(num % 3 == 0) { num /= 3; } while(num % 5 == 0) { num /= 5; } return num == 1; } }
相关文章推荐
- [Qt] Mask 蒙版
- Learning Spark - LIGHTNING-FAST DATA ANALYSIS 第三章 - (3)
- 【转】电子商务网站测试经验总结
- 系统性能指标
- 2015 ACM/ICPC Asia Regional Shanghai Online
- Android中的Touch事件处理流程
- TCP成块数据流
- [Qt] searchBox 搜索框实现
- Linux驱动知识点汇总
- 杭电acm--2024
- c++设计模式-----中介者模式Mediator
- opengl glBegin() glEnd() 中常用函数
- 瞬时动作的函数
- RA layer request failed SVN
- 无题1
- HDU5478取模恒等式
- java求几个数字的和输出详细步骤
- [Qt] searchBox 搜索框实现
- 二
- 开始自己的技术博客生涯