Description:

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, 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.

寻找丑数:

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; }
}

LeetCode——Ugly Number的更多相关文章

  1. 力不从心 Leetcode(ugly number heap) 263, 264,313

    Leetcode ugly number set (3 now) new ugly number is generated by multiplying a prime with previous g ...

  2. [LeetCode] Ugly Number II 丑陋数之二

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

  3. [LeetCode] Ugly Number 丑陋数

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

  4. [LeetCode] Ugly Number II

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

  5. [LeetCode] Ugly Number

    Ugly Number Total Accepted: 20760 Total Submissions: 63208 Difficulty: Easy Write a program to check ...

  6. [LeetCode] Ugly Number II (A New Question Added Today)

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

  7. [LeetCode] Ugly Number (A New Question Added Today)

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

  8. LeetCode() Ugly Number II 背下来!

    一个别人,非常牛逼的思路,膜拜了!orz!!!! vector <int> results (1,1); int i = 0, j = 0, k = 0; while (results.s ...

  9. LeetCode Ugly Number (简单题)

    题意: 判断是一个数的质因子仅含有2,3,5这3个. 思路: 因子2比较容易解决,num/=num-(num&num-1)就可以了.3和5的需要通过循环来另判. C++ class Solut ...

随机推荐

  1. c#生成rsa公钥和私钥

    c#生成rsa公钥和私钥的类库,包括加密解密,可以用在网站和winform项目 源码地址: http://download.csdn.net/detail/jine515073/8383809

  2. 教你如何做一个优雅的Ecmascripter /转

    看看这些被同事喷的JS代码风格你写过多少 殷荣桧 JavaScript 今天 现在写代码比以前好多了,代码的格式都有eslint,prettier,babel(写新版语法)这些来保证,然而,技术手段再 ...

  3. ★ java删除代码注释

    package com.witwicky.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java ...

  4. laravel 参数配置

    1:在项目根目录下有个叫.env的文件.这个文件是配置配置.由config文件下的app.php 直接读取. #参数解释 APP_ENV=local #访问地址 APP_DEBUG=true #是否开 ...

  5. CSS圆角框,圆角提示框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 关于PHP开发所需要的工具和环境

    0.notepad++ 一个类型记事本的软件,用来看安装的部署说明命令. 1.虚拟机 在虚拟机里面操作,本机不会被影响. 2.CentOS系统 类似Linux的系统,在里面安装PHP,Nginx,ph ...

  7. Spring IO platform 简介

    前提:熟悉Spring基础知识. 简介:Spring IO Platform将 the core Spring APIs 集成到一个Platform中.它提供了Spring portfolio中的大量 ...

  8. getaddrinfo ENOTFOUND https://api.weixin.qq.com https://api.weixin.qq.com:443

    原因:这是由于你当前的主机不能够连接到你填写的url. 解决方法: 先ping api.weixin.qq.com ping不通的话,就是外网访问的问题. 开通外网访问就可以了.

  9. (转)PS流格式

    概念: 将具有共同时间基准的一个或多个PES组合(复合)而成的单一的数据流称为节目流(Program Stream). ES是直接从编码器出来的数据流,可以是编码过的视频数据流,音频数据流,或其他编码 ...

  10. 用X264编码以后的H264数据

    输入的数据准备好了,编码后的数据都在x264_nal_t的数组.我这里设置的参数是Baseline Profile,所以编码后没有B帧,将编码后的数据保存分析后发现,第一次编码的时候会有4个NAl,分 ...