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.

实现:

class Solution {

public:

    bool isUgly(int num) {

        if (num == 0) return false;

        if (num == 1) return true;

        if (num % 2 == 0) return isUgly(num/2);

        else if (num % 3 == 0) return isUgly(num/3);

        else if (num % 5 == 0) return isUgly(num/5);

        return false;

    }

};

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

  1. LeetCode----263. Ugly Number(Java)

    package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...

  2. LeetCode263:Ugly Number

    public bool IsUgly(int num) { if(num<1) return false; while(num>1) { if(num%2==0) { num=num/2; ...

  3. [Swift]LeetCode263. 丑数 | Ugly Number

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

  4. [LeetCode] Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

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

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

  6. [LeetCode] Ugly Number 丑陋数

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

  7. 【13_263】Ugly Number

    简单题 Ugly Number My Submissions Question Total Accepted: 32635 Total Submissions: 94009 Difficulty: E ...

  8. Leetcode 313. super ugly number

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  9. Leetcode 264. Ugly Number II

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

随机推荐

  1. 〖Linux〗ADT_Bundle配置

    1. 配置自动补全: Windows -> preferences -> 搜索assist,修改 java xml自动触发补全:.abcdefghijklmnopqrstuvwxyzABC ...

  2. 〖Linux〗Ubuntu13.10搭建文件共享Samba服务器

    1. 安装 $ sudo apt-get install samba 2. 配置smb用户密码 # cat /etc/passwd | mksmbpasswd > /etc/samba/smbp ...

  3. LeetCode 225 Implement Stack using Queues(用队列来实现栈)(*)

    翻译 用队列来实现栈的例如以下操作. push(x) -- 将元素x加入进栈 pop() -- 从栈顶移除元素 top() -- 返回栈顶元素 empty() -- 返回栈是否为空 注意: 你必须使用 ...

  4. linux tftp 服务

    TFTP(Trivial File Transfer Protocol)是基于UDP协议开发,用来在客户机与server之间进行简单文件传输的协议,提供不复杂.开销不大的文件传输服务. 一.改动/et ...

  5. 主成分分析PCA

    PCA(Principal Component Analysis)不仅仅是对高维数据进行降维,更重要的是经过降维去除了噪声,发现了数据中的模式. PCA把原先的n个特征用数目更少的m个特征取代,新特征 ...

  6. SpannableStringUtil实现丰富文字效果

    代码地址如下:http://www.demodashi.com/demo/15007.html 前言 在android开发中,我们不免会用到 TextView 的各种显示效果,如字体样式,颜色,大小, ...

  7. [翻译]01-ASP.NET MVC 3介绍

    前言 -------------------------- 最近,公司新架构使用asp.net mvc5,一直都是看书学习ASP.NET MVC的,书本毕竟是别人翻译过来的,所以里面可能某些地方翻译有 ...

  8. 屏蔽alert弹框下面一层的操作

    需求: 给alert框戴个套. 屏蔽下层页面的操作. 搞这个花里胡哨的东西. 还一baidu全都是长得一样的答案. 神魔恋. /** * Tip Message像alert一样 */ function ...

  9. [Spring学习笔记 3 ] spring 注解详解,完全注解,常用注解

    .xml使用注解 xml 用来定义bean的信息,注解用来配置依赖信息 ) 在配置文件中配置bean )在javaBean中用注解来指定依赖注入 )在配置文件中开启注解扫描 @Resource标签 j ...

  10. iptables中ULOG和NFLOG实现分析【转】

    原文地址:http://blog.csdn.net/eydwyz/article/details/52456335 ----------原文如下---------------------------- ...