Algorithms—263.Ugly Number
2015-08-24 14:55
387 查看
思路:2,3,5依次尝试,能整除则整除,不能整除则返回false,整除到1则返回true
public class Solution {
public boolean isUgly(int num) {
if (num==0) {
return false;
}
while (num!=1) {
if (num%2==0) {
num/=2;
}else if (num%3==0) {
num/=3;
}else if (num%5==0) {
num/=5;
}else {
return false;
}
}
return true;
}
}
耗时:256ms。
public class Solution {
public boolean isUgly(int num) {
if (num==0) {
return false;
}
while (num!=1) {
if (num%2==0) {
num/=2;
}else if (num%3==0) {
num/=3;
}else if (num%5==0) {
num/=5;
}else {
return false;
}
}
return true;
}
}
耗时:256ms。
相关文章推荐
- Algorithms—268.Missing Number
- hdoj 1533 Going Home 【最小费用最大流】【KM入门题】
- Hierarchical Clustering(学习Free Mind知识整理)和Hungarian Algorithm
- leetcode: (21) Merge Two Sorted Lists
- 故障管理系统--select两级联动查询
- 使用Go快速创建静态服务
- C4D制作毛发舞动的Logo
- 加了GO后报 'GO' 附近有语法错误
- Unix 哲学:Elixir 将会替代 Go
- ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
- GoldenGate碎碎念
- Benefits of Cold Showers: 7 Reasons Why Taking Cool Showers Is Good For Your Health
- GOF 23种设计模式目录
- django celery异步框架
- 安装与初始配置
- POJ 2195 Going Home(二分图最大权值匹配) KM
- leetcode: (6) ZigZag Conversion
- 【英语】Bingo口语笔记(57) - 常见的口语弱读
- 【英语】Bingo口语笔记(56) - “令人失望”的表达
- Django1.4上传图片无法在页面显示的问题