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. 构建基于分布式SOA架构的统一身份认证体系

    摘要:本文充分利用SOA架构松耦合的特点,通过规范统一网络接口实现业务系统整合,既提升系统安全性,又简化资源访问操作,具有重要的理论和现实意义. 统一身份认证旨在将分散在各个信息系统中的用户和权限资源 ...

  2. WF追忆

    前一阵子学习了一下工作流,现在写个总结记录一下这个过程.要弄工作流,首先就要有个界面来画图,做web的,没办法,只能选择javascript和silverlight,找来找去,最后用了Shareide ...

  3. 网络配置vlan

    1. # This file describes the network interfaces available on your system # and how to activate them. ...

  4. 判断radiobutton是否被选中

    <tr> <td class="label">是否显示:</td> <td> <?php if($cates_data[0][ ...

  5. Spring 4 官方文档学习(十)数据访问之DAO支持

    1.介绍 Spring 中 Data Access Object (DAO)支持 的目标是以一种一致的方式更简单的使用JDBC.Hibernate.JPA或JDO等数据访问技术.可以在前面说的几种数据 ...

  6. 使用ffmpeg获取视频流后如何封装存储成mp4文件

    int main(int argc,char *argv[]) 02 { 03  AVFormatContext *pFormatCtx; 04  int i,videoStream; 05  AVC ...

  7. struct iphdr中的__LITTLE_ENDIAN_BITFIELD和__BIG_ENDIAN_BITFIELD

    __LITTLE_ENDIAN_BITFIELD表示小端序,__BIG_ENDIAN_BITFIELD表示大端序. /usr/include/linux/ip.h中有一段代码定义了ip首部的结构体,例 ...

  8. 利用circpedia 数据库探究circRNA的可变剪切

    circpedia 中收录了利用circexplorer 软件识别到的circRNA, 覆盖了人,小鼠,鸟类,昆虫多个物种的多种细胞系的数据 官网链接如下: http://www.picb.ac.cn ...

  9. 公式编辑器编辑倒L符号的方法

    数学公式全都是由数字字母和一些符号组成的,一些常用的字母符号我们使用起来也很熟练,但是在数学中也有一些符号是比较少用的,比如倒着的L,这个符号在一些函数中出现过,表示某一类的函数.在word公式编辑器 ...

  10. python编码问题1

    爬虫,新手很容易遇到编码解码方面的问题.在这里总结下. 如果处理不好编码解码的问题,爬虫轻则显示乱码,重则报错UnicodeDecodeError: 'xxxxxx' codec can't deco ...