1. package isUgly263;
  2. /*
  3. * Write a program to check whether a given number is an ugly number.
  4.  
  5. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
  6.  
  7. Note that 1 is typically treated as an ugly number.
  8. */
  9. public class Solution {
  10. public static boolean isUgly(int num) {
  11. if (num<=0)
  12. return false;
  13. while(num>5){
  14. if(num%2==0)
  15. num=num/2;
  16. else if(num%3==0)
  17. num=num/3;
  18. else if(num%5==0)
  19. num=num/5;
  20. else
  21. return false;
  22. }
  23. return true;
  24. }
  25. public static void main(String[] args) {
  26. // TODO Auto-generated method stub
  27. int num=14;
  28. System.out.println(isUgly(num));
  29. }
  30.  
  31. }

LeetCode----263. Ugly Number(Java)的更多相关文章

  1. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  2. LN : leetcode 263 Ugly Number

    lc 263 Ugly Number lc 263 Ugly Number Write a program to check whether a given number is an ugly num ...

  3. Java [Leetcode 263]Ugly Number

    题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive n ...

  4. [LeetCode] 263. Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  5. LeetCode 263 Ugly Number

    Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...

  6. Leetcode 263 Ugly Number 数论 类似质因数分解

    Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...

  7. (easy)LeetCode 263.Ugly Number

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  8. [leetcode] 263. Ugly Number (easy)

    只要存在一种因数分解后,其因子是2,3,5中的一种或多种,就算是ugly数字. 思路: 以2/3/5作为除数除后,最后结果等于1的就是ugly数字 Runtime: 4 ms, faster than ...

  9. [LeetCode] 264. Ugly Number II 丑陋数 II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  10. 263. Ugly Number(C++)

    263. Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are ...

随机推荐

  1. ArcGIS AddIN开发之COM对象写入注册表

    做一个交互式绘制文字的工具,希望这次设置的Symbol,下次打开ArcMap时自动调用这个Symbol,并支持对其进行修改. 解决方法是将这个Symbol写入注册表中,每次自动读取上一次设置的Symb ...

  2. UIBezierPath 的使用

    使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线 ...

  3. Hibernate saveOrUpdate方法到底是怎么执行的?

    saveOrUpdate方法,如果传入的对象有主键就执行更新,没有就执行新增.这句话误导了很多人. 究竟是执行新增还是更新,是要有上下文环境的.这个环境就是主键策略的选择. 主键生成方式为 手动设置: ...

  4. ubuntu安装Python环境以及科学计算环境

    参考:http://blog.csdn.net/a1311543690/article/details/ 1.sudo apt-get install python-pip pip是Python的一个 ...

  5. 浅谈scrum站立会议

    什么是每日站立会议?       站立会议是让团队成员每日面对面站立互相交流他们所承担任务的进度.它的一个附带好处是让领导或经理能了解到工作情况.但本质上是为了团队交流,不是报告会议! 为什么开展每日 ...

  6. geometric median

    The geometric median of a discrete set of sample points in a Euclidean space is the point minimizing ...

  7. iOS 3D touch 使用技巧

    第一个 在桌面中3d Touch 打开菜单 由于本人纯属代码党,本次实现方法也只使用代码实现 到达到这个效果并不难,只需要在appdelegate中实现以下代码即可 ,当然也有缺点,就是这个app没运 ...

  8. PHPExcel导出数据

    require_once './class/Excel/PHPExcel.php'; //将(1,1)转换成"A1"形式 function getCoordinate($row, ...

  9. Android RecyclerView的基本使用

    Android RecyclerView 在去年的Google I/O大会上就推出来了,以前经常使用的ListView 继承的是AbsListView,而RecyclerView则直接继承 ViewG ...

  10. View的drawRect方法

    1)此方法在View第一次在展示时调用,此后都用他的一个shotCut,可用setNeedsDisplay方法强制调用. 1)此方法在ViewDidAppear方法中才会调用.因此要想获得在drawR ...