【LeetCode】Ugly Number 解题报告
2015-10-16 21:25
323 查看
Ugly Number
[LeetCode]https://leetcode.com/problems/ugly-number/
Total Accepted: 22335 Total Submissions: 67449 Difficulty: Easy
Question
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.
Examples
For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.Note that 1 is typically treated as an ugly number.
Ways
方法一
把这个数中的所有的2,3,5的因子全部除去,剩余的数为1,则说明全部为这几个因子构成[code]public static boolean isUgly(int num) { if (num == 1) { return true; } while (num >= 2 && num % 2 == 0) { num = num / 2; } while (num >= 3 && num % 3 == 0) { num = num / 3; } while (num >= 5 && num % 5 == 0) { num = num / 5; } return num == 1; }
Solution
托管在我的GitHub上:https://github.com/fuxuemingzhu/UglyNumber
Captures
测试结果截图:Reference
http://blog.csdn.net/xudli/article/details/47786867Date
2015/10/16 21:20:23相关文章推荐
- 第二章、供应源搜寻战略
- android学习
- 【面试题】C语言:使用函数实现两个数的交换
- Android学习之Activity生命周期
- scikit-learn preprocessing模块
- servlet
- gtest入门简介
- ios申请真机调试( xcode 5)详细解析
- 参考了《简单的3步设置,让你的博客园更漂亮!》,让博客清爽、美观,心情美美哒(>_<)
- sharepreference使用方法
- [POJ2456]Aggressive cows
- 一、门级结构描述
- findViewById
- 日经春秋 20151016
- 判断物体是否在镜头内
- 第一次向pypi添加一个新的库
- JSON文件处理
- BSD socket编程学习
- 网络摄像机画面卡顿的主要原因有哪些?
- android学习资源